Apple Automator: Difference between revisions
(16 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
I have looked on the Internet to find good tutorials and decided to collect the best ones. | I have looked on the Internet to find good tutorials and decided to collect the best ones. | ||
== Create New File == | |||
To create a folder is already covered in the services. This one will make it possible to create a New (text)-file in a folder. You need to stand on the folder-name to see this service. | |||
* Start ''Automator'' and create a new '''Service'''. | |||
* Set the ''Service'' to receive "folders". | |||
* Set the application to ''Finder''. | |||
* Drag and drop the action ''Run AppleScript'' into the work area. | |||
* Paste the following AppleScript: | |||
<pre> | |||
on run {input, parameters} | |||
tell application "Finder" | |||
set currentPath to insertion location as text | |||
set x to POSIX path of currentPath | |||
end tell | |||
return x | |||
end run | |||
</pre> | |||
* Drag and drop the action ''Set value of a variable'' into the work area. | |||
* Create a new variable called ''CurrentFolder''. | |||
* Drag and drop the action ''New Text File'' into the work area. | |||
* Drag the variable ''CurrentFolder'' to the ''Where'' entry of the ''New Text File'' action. | |||
* Click the ''Option'' button in the action, and select ''Show this action when the workflow runs''. | |||
== Batch rename == | |||
[[File:Rename-Finder-Items.png|thumb|350px|right|Service rename files]] | |||
The Automator.app has allowed batch-renaming files, but it has always been pretty slow, because it created PowerPC binaries. <ref>[https://kkaefer.com/note/batch-rename-on-lion/ Konstantin Käfer], Author of the Batch rename article.</ref> | |||
<br>Fortunately, in Mac OS X 10.7, Automator.app got really fast, making it a lot more useful. | |||
* Start ''Automator'' and create a new '''Service'''. | |||
* Select '''files or folders''' at the top. | |||
* In the left sidebar, search for '''Rename Finder Items''', and drag it the ''main pane''. | |||
* In the modal box, click '''Don’t Add'''. | |||
* Click on '''Options''' in the new workflow segment and check ''Show this action when the workflow runs''. | |||
* In the File Menu, click '''Save''' and name it ''Rename files''. | |||
* Now you can select files in the ''Finder'', go the application menu, hover over '''Services''', and click ''Rename''. | |||
** In the upcoming Window choose in the Combo-box for ''Rename text'', which imho is the most used feature. | |||
== Get File Path == | |||
[[File:GetFilePathAMA-en.png|thump|350px|right|Automator Action Get File Path]] | |||
The ''Get File Path action'' which is an essential part for copy the full path of a file to the clipboard is my favourite action. | |||
<br>Unfortunately this action is not a basic building block in Automator. | |||
<br>You can download the Action from [http://www5.wind.ne.jp/miko/mac_soft/automator_actions/hqx/GetFilePathAMA_1.0.zip here] <ref>[http://www5.wind.ne.jp/miko/mac_soft/automator_actions/pgs/GetFilePathAMA-en.html MiKo Mac_Soft], Automator action to get file/folder path with POSIX/HFS/URL format</ref>. | |||
To instal an Action do: | |||
# Doube click the archive file (.zip file) to unarchive it if you received your Action packed in an archive or zip-file. | |||
# Launch Automator application, | |||
# Select ''Import Actions'' from Automator File menu, | |||
# Choose the action (.action file) to install or double click the action to install if your Mac OS X is Snow Leopard or later. | |||
== Synchronize Folders == | == Synchronize Folders == | ||
Line 41: | Line 90: | ||
</pre> | </pre> | ||
# Please not that you can add the option '''--delete''' to the rsyc, but don't do that in the first test run. | # Please not that you can add the option '''--delete''' to the rsyc, but don't do that in the first test run. | ||
== Pop-up Window == | |||
Looking for a popup window for Apple OSX? Here is terminal-notifier. To install: | |||
sudo gem install terminal-notifier | |||
This works better than osascript because that will give you an error message when you try to use arguments. The sources are also available at: | |||
https://github.com/alloy/terminal-notifier.git | |||
== See also == | == See also == | ||
<span class="editsection">[[#content|top]]</span> | <span class="editsection">[[#content|top]]</span> | ||
* [http://macosxautomation.com/automator/examples/workflows.html Apple | * [http://macosxautomation.com Mac OSX Automation], Home Page | ||
** [http://macosxautomation.com/automator/examples/workflows.html Apple MacOSX] Automator Examples Workflows. | |||
** [http://macosxautomation.com/services/download Services] download | |||
* [http://www.maclife.com/article/features/15_automator_and_applescripts_you_can’t_live_without MacLife], 15 Automator and AppleScript you can not live without. | |||
* [http://automatorworld.com Automator World], Better livinf through Apple's Mac Scripting | |||
* [http://veritrope.com/os-x-services Veritrope], List of OS-X-Services | |||
== Reference == | == Reference == |
Latest revision as of 09:01, 4 May 2013
Automator is a funny tool, but a good tutorial of using it is lacking. I really miss some good Automator tutorials online. It's such a great and I guess underrated and underused tool. Here I'll show you how to combine it with rsync to easily synchronise two folders. I have looked on the Internet to find good tutorials and decided to collect the best ones.
Create New File
To create a folder is already covered in the services. This one will make it possible to create a New (text)-file in a folder. You need to stand on the folder-name to see this service.
- Start Automator and create a new Service.
- Set the Service to receive "folders".
- Set the application to Finder.
- Drag and drop the action Run AppleScript into the work area.
- Paste the following AppleScript:
on run {input, parameters} tell application "Finder" set currentPath to insertion location as text set x to POSIX path of currentPath end tell return x end run
- Drag and drop the action Set value of a variable into the work area.
- Create a new variable called CurrentFolder.
- Drag and drop the action New Text File into the work area.
- Drag the variable CurrentFolder to the Where entry of the New Text File action.
- Click the Option button in the action, and select Show this action when the workflow runs.
Batch rename

The Automator.app has allowed batch-renaming files, but it has always been pretty slow, because it created PowerPC binaries. [1]
Fortunately, in Mac OS X 10.7, Automator.app got really fast, making it a lot more useful.
- Start Automator and create a new Service.
- Select files or folders at the top.
- In the left sidebar, search for Rename Finder Items, and drag it the main pane.
- In the modal box, click Don’t Add.
- Click on Options in the new workflow segment and check Show this action when the workflow runs.
- In the File Menu, click Save and name it Rename files.
- Now you can select files in the Finder, go the application menu, hover over Services, and click Rename.
- In the upcoming Window choose in the Combo-box for Rename text, which imho is the most used feature.
Get File Path

The Get File Path action which is an essential part for copy the full path of a file to the clipboard is my favourite action.
Unfortunately this action is not a basic building block in Automator.
You can download the Action from here [2].
To instal an Action do:
- Doube click the archive file (.zip file) to unarchive it if you received your Action packed in an archive or zip-file.
- Launch Automator application,
- Select Import Actions from Automator File menu,
- Choose the action (.action file) to install or double click the action to install if your Mac OS X is Snow Leopard or later.
Synchronize Folders
This example script is in basic taken from Bananical [3], but with a few enhancements to make errors less severe. The script describes real mic what and how you can use Automator to script you results
The script uses the UNIX rsync command [4]. Please take care in using this script. It may be dangerous to use.
- Start Automator application and choose the Workflow as template for your Workflow.
- Add the action Ask for Finder Items from the category Files & Folders or use the search option to find it.
- Change the text of the Prompt field into Choose a folder to synchronize from.
- Select the folder for the Start at field into your folder of choice.
- Change Type into Folders.
- Add action Set value for Variable and give the variable the name source_folder.
- Now ctrl-click (or right click) on the text field and select Ignore input from the popup-window.
- Repeat Step 2: Add the action Ask for Finder Items
- Change the text of the prompt into Choose a Target folder.
- Repeat Step 4: Add action Set value for Variable and give the variable the name target_folder.
- Add action Ask for Confirmation
- Change the prompt into Synchronizing from .
- Drag the Variable source_folder into the prompt field.
- and the text to
- Drag the Variable target_folder into the prompt field.
- Again, ctrl-click (or right click) on the text field and select Ignore input from the popup-window.
- Now add Get Value of Variable for the source_folder and add Ignore the input.
- Again add Get Value of Variable for the source_folder and add Ignore the input.
- Add the action Run Shell Script. Add the following text:
if [[ -z $1 ]] ; then echo "Invalid choice for Source ($1), aborting" exit -1 fi if [[ -z $2 ]] ; then echo "Invalid choice for Target ($2), aborting" exit -1 fi rsync -va "$1/" "$2/"
- Please not that you can add the option --delete to the rsyc, but don't do that in the first test run.
Pop-up Window
Looking for a popup window for Apple OSX? Here is terminal-notifier. To install:
sudo gem install terminal-notifier
This works better than osascript because that will give you an error message when you try to use arguments. The sources are also available at:
https://github.com/alloy/terminal-notifier.git
See also
- Mac OSX Automation, Home Page
- Apple MacOSX Automator Examples Workflows.
- Services download
- MacLife, 15 Automator and AppleScript you can not live without.
- Automator World, Better livinf through Apple's Mac Scripting
- Veritrope, List of OS-X-Services
Reference
- ↑ Konstantin Käfer, Author of the Batch rename article.
- ↑ MiKo Mac_Soft, Automator action to get file/folder path with POSIX/HFS/URL format
- ↑ Bananica, Synchronize 2 folders on Mac.
- ↑ Linux.die.net, man page for rsync.