0

I want to start a simple shell script in automator and save it as an application.

How do I realize this: I drag a folder to my new application, the terminal command is a simple 'ls' of that folder, I want to output that ls result to a text file under ~/Desktop/test.txt

and open that test.txt in a text editor.

What I did already is create a new automator app and run a shell script and type ls

and I see nothing

how can I realize this?

and BTW I want to use the run shell script part, because I want to use this technique for other terminal commands

2 Answers 2

1

When you drag items onto your Automator application, the paths are passed to the actions in your workflow, where each action works with its input, and passes the results on to the next action. In your shell script action, you will need to use the action’s input as arguments to your script, and its results will need to be passed on to something that will provide the output you are looking for, for example New Text File. An example workflow would be:

  • Application receives files and folders as input
  • Run Shell Script { Pass input: as arguments }:

    for f in "$@"
    do
      ls "$f"
    done
    
  • New Text File { File Format: Plain text, Save as: whatever, Where: Desktop }

Sign up to request clarification or add additional context in comments.

1 Comment

ahhh great that works! After that I added Get Specified Finder Items and I choose my text file and after that I choose open finder Items and I choose sublime Text. Thanks for helping me get started :-)
1

No need to add extra steps after the "Run Shell Script" command, to your Automator workflow (Get Specified Finder Items... etc). The "Run Shell Script" command can handle all of the actions you are looking to achieve. See if this works for you.

for f in "$@"
do 
ls "$f" > ~/Desktop/test.txt ; open -a '/Applications/Sublime Text.app' ~/Desktop/test.txt 
done 

1 Comment

yes that works great, tested it. I only need one shell script, thanks, great tip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.