Automator - Set Selected Folder Path as Variable

5,942

So I took a slightly different route, and just setup a shell script. Apparently cd "$@"; will get the current directory. View a picture of my new automator service workflow.

Basically, I created a new service in Automator, then set Service Receives Selected to "files or folders" in "Finder", and added a "Run Shell Script" to the workflow. I set Shell to "/bin/bash", and Pass Input to "as arguments", then placed the following in the script editor.

cd "$@";
curl -O http://www.example.com/file1.zip
curl -O http://www.example.com/file2.zip
curl -O http://www.example.com/file3.zip
unzip \*.zip
rm *.zip

Now I can right click on any folder, and download my list of files.

Share:
5,942

Related videos on Youtube

Kelly Lawrence
Author by

Kelly Lawrence

Updated on September 18, 2022

Comments

  • Kelly Lawrence
    Kelly Lawrence almost 2 years

    I'm trying to setup an Automator service that would download a list of URLs to the currently selected folder, or wherever the service was ran from. The only problem is I don't see how I would go about setting the currently selected folder as a path to download the files to. I'm thinking of something like this:

    Screenshot of my Automator idea

    Note: Just realized I had service receives selected as "TEXT in ANY APPLICATION" in my screenshot. This will be "FOLDERS in FINDER" when I hopefully get this figured out!

    Where currentFolder currently selected folder, or wherever the service was ran from. As far as I can tell, I would just need to somehow set the currently selected folder as a variable like currentFolder, then set the Download URLs location to that variable? Let me know if I need to explain anything further!

  • Kelly Lawrence
    Kelly Lawrence almost 11 years
    Thank you very much for your answer sajjadG! I'm not very familiar with the Automator program, so I'm sorry beforehand if this should be pretty obvious, but would I place the commands you've listed in as an AppleScript or a Shell Script? Also, in what order would I place these? I would assume $currentDir=$PWD at the very start, and $export currentDir just before setting the download location?
  • sajjadG
    sajjadG almost 11 years
    @KellyLawrence sorry but I am not familiar with automator but wikipedia says that both of them will work. automaro can use both unix command line scripts (which is what I posted) and AppleScripts.
  • Kelly Lawrence
    Kelly Lawrence almost 11 years
    No worries @sajjadG! I appreciate you taking the time to provide an answer. As you can see in my answer below, I took a slightly different approach after doing some more research, but the end goal was achieved, regardless!
  • slhck
    slhck almost 11 years
    This will only work if you select one folder. $@ expands to all arguments passed to the script, so if you select multiple folders or even files, cd doesn't know what to do with them. I'll try and see if I can come up with an alternative.