Pinterest Stumbleupon Whatsapp
Ads by Google

applescript automatorIn part one of my introductory article Learn to Automate Your Mac with AppleScript [Part 1: Introduction] Learn to Automate Your Mac with AppleScript [Part 1: Introduction] Read More about Apple”˜s automation program, AppleScript, I explained how to basically access this application and use a few of the default scripts that come with every version of Mac OS X. In part two of this article I will explain how to use a few cool and practical automation scripts that you might find useful.

With the following instructions, I assume that you have read the overview in part one of this series.

Move To Folder

The following script, when activated, will put all the files on your desktop into a folder and name that folder “screenshots”, or whatever name you designate. I use this script because I take several screenshots a day for articles like this one.

  1. Launch AppleScript and copy and paste the following code in the editor.

    set folder_name to “screenshots”

    tell application “Finder”

    set archive_folder to make new folder at desktop ¬

    with properties {name:folder_name}

    move every file of desktop to archive_folder

    end tell

  2. Click the Compile button in the AppleScript toolbar. It should look similar to the script above. You can of course customize the label “screenshots”.
  3. To test this script, put some files (not folders) on your desktop, and then click the Run button in AppleScript. It should move those files into a folder and label it.
  4. Finally, save the script as an application and put it both in your Application’s folder and in your dock and run as needed. This script saves you a few steps and clicks when you’re working at your computer.

applescript automator

Folder Action Script

One of the best kind of automations is folder actions 2 Useful Tips For Organizing Electronic Files [Mac Only] 2 Useful Tips For Organizing Electronic Files [Mac Only] Read More because since we typically move stuff into folders anyway we might as well use a few to automate a redundant task or two.

Ads by Google

This automation will open your Shared folder when one or more items are dropped into it.

  1. Copy and paste the following code in the AppleScript editor:

    on adding folder items to theFolder after receiving theItems

    tell application “Finder”

    make new Finder window to folder “Shared” of folder “Users” of startup disk

    set position of Finder window 1 to {500, 236}

    end tell

    end adding folder items to

  2. Compile the script to make sure it’s OK. Save it in your User Library > Scripts  > Folder Actions folder. If this folder doesn’t exist, you can simply create one. You can title it something like, “OpenShareFolder“.
  3. Now click on the AppleScript icon in your menu bar (this was covered in part one of the article) and select the Folders Action folder.
  4. applescript automator

  5. Select and run the Enable Folder Actions script so that folder actions will work on your Mac.
  6. Now go back to that same folder and select and run Attach Script to Folder.
  7. It will open a list of Folder Actions on your computer. Find and select the folder action script you just saved. Click OK.
  8. folderactions.png

  9. Next you will be prompted to choose a folder to attach the selected script to. In this case, select your Shared folder on your Mac. Click Choose.

Now whenever an item is dropped into your shared folder, the attached AppleScript will open your folder for you.

These are just a few examples of what can be done with AppleScript. Let us know how they work for you. In the final part of this series, I will share some free resources for learning more about AppleScript.

  1. MuscArto
    December 3, 2010 at 4:42 am

    have never learned to work with AppleScript or Automator .
    but after this tutorial
    i will sure try this :)

    thanks

  2. MuscArto
    December 3, 2010 at 5:42 am

    have never learned to work with AppleScript or Automator .
    but after this tutorial
    i will sure try this :)

    thanks

  3. Bakari
    November 5, 2010 at 1:57 am

    Hi Anthony, I’m not an advanced AppleScripter, but for what you’re trying to do (I don’t understand it all), you should take a look at Automator. With that program, I know you can create a workflow in which when you drop files onto a workflow saved as an app(droplet), it will copy selected files to a new folder, and it will give you the opportunity to customize the name of that folder before it’s saved to the designated place on your Finder.

    For the last part of your what you need, you could try a really cool program called Hazel. If you’re working with lots of files and folders that need to be moved and copied, that program can do the job.

    Both Automator and Hazel require no AppleScripting code. But if you still want to do it in AppleScript, give this forum a try: http://macscripter.net/viewtopic.php?id=24599.

    Finally, if you’re not getting anywhere with all this, create a video capture of the steps in the process you want done, post it somewhere, and I’ll take a look at it to see what I can come up with.

    Sorry I couldn’t be of more help.

  4. Bakari
    November 5, 2010 at 2:57 am

    Hi Anthony, I’m not an advanced AppleScripter, but for what you’re trying to do (I don’t understand it all), you should take a look at Automator. With that program, I know you can create a workflow in which when you drop files onto a workflow saved as an app(droplet), it will copy selected files to a new folder, and it will give you the opportunity to customize the name of that folder before it’s saved to the designated place on your Finder.

    For the last part of your what you need, you could try a really cool program called Hazel. If you’re working with lots of files and folders that need to be moved and copied, that program can do the job.

    Both Automator and Hazel require no AppleScripting code. But if you still want to do it in AppleScript, give this forum a try: http://macscripter.net/viewtop...

    Finally, if you’re not getting anywhere with all this, create a video capture of the steps in the process you want done, post it somewhere, and I’ll take a look at it to see what I can come up with.

    Sorry I couldn’t be of more help.

  5. anthony
    November 3, 2010 at 10:46 pm

    Hi Bakari, I see you are very proficient in AppleScripting, I need your help, if, of course, is not much trouble for you...

    I'm moving from Windows, I have huge file collection and I'm very urgently need a script, more specifically a droplet, to do the following:

    1. I drop a file or a bunch of files on it
    2. It is reading the file (s) name, which is format 2009_12_03 Status of... something
    3. Will wait from an input from me, byl pop a window asking "Put here the folder name"
    4. The script will create a folder, with name concatenating "part of original file"_"input folder name from me", always into a home folder, that I declare at the beginning of script (so the newly created folder is always in the same designated folder, folder that I will define myself i the script)
    5. After this folder is created, script will copy the respective file (from which the first part of name is taken, that of date) into this newly created folder, with same name and extension as is when is dropped on the droplet (no changing the file name)

    I tried different approaches, but without good results, I'm always blocked at POSIX, get many error messages, etc and I have to move fast with the huge number of files...

    Thank you very much,
    Anthony

  6. anthony
    November 3, 2010 at 11:46 pm

    Hi Bakari, I see you are very proficient in AppleScripting, I need your help, if, of course, is not much trouble for you...

    I'm moving from Windows, I have huge file collection and I'm very urgently need a script, more specifically a droplet, to do the following:

    1. I drop a file or a bunch of files on it
    2. It is reading the file (s) name, which is format 2009_12_03 Status of... something
    3. Will wait from an input from me, byl pop a window asking "Put here the folder name"
    4. The script will create a folder, with name concatenating "part of original file"_"input folder name from me", always into a home folder, that I declare at the beginning of script (so the newly created folder is always in the same designated folder, folder that I will define myself i the script)
    5. After this folder is created, script will copy the respective file (from which the first part of name is taken, that of date) into this newly created folder, with same name and extension as is when is dropped on the droplet (no changing the file name)

    I tried different approaches, but without good results, I'm always blocked at POSIX, get many error messages, etc and I have to move fast with the huge number of files...

    Thank you very much,
    Anthony

  7. Ciaran
    October 30, 2010 at 11:35 am

    You need to replace the curly quotation marks with normal ones.

    For example “Finder” becomes "Finder".

  8. Bakari
    October 30, 2010 at 10:11 am

    Zane, instead of copying and pasting script, type it out and when you get to the line ending with “desktop”, do an option-return and proceed with the following lines. Let me know if that works.

  9. Bakari
    October 30, 2010 at 8:11 am

    Zane, instead of copying and pasting script, type it out and when you get to the line ending with “desktop”, do an option-return and proceed with the following lines. Let me know if that works.

  10. Zane
    October 30, 2010 at 5:32 am

    when i copied and pasted, it said "syntax error: expected expression, but found unknown token"

    • Ciaran
      October 30, 2010 at 9:35 am

      You need to replace the curly quotation marks with normal ones.

      For example “Finder” becomes "Finder".

    • Bakari
      November 2, 2010 at 4:29 pm

      Thanks, Ciaran, for the clarification.

Leave a Reply

Your email address will not be published. Required fields are marked *