Automator is a nifty solution in Mac OS X for, well, automating frequent tasks. If an application publishes actions to the operating system, the user can construct a workflow/application that pipes operations from one app to another. There aren’t yet, as of this writing, actions which enable one to capture the filename of a file. However, a workflow can use an AppleScript as a workflow step.
The following script may be used in an Automator workflow to capture a file name to the clipboard:
on run {input, parameters} set thePath to quoted form of POSIX path of input do shell script "basename " & thePath set the clipboard to the result return input end run
I use this script in a workflow which does the following:
- Accept a file from the Finder.
- Capture filename to the clipboard.
- Modify text contents using a TextSoap filter.
- Modify text contents using another TextSoap filter.
- Upload the modified file to an SFTP server using Fetch.
Then I hop into a Terminal/SSH session and paste the filename into a command. If I were extra-clever, I’d jimmy this further into executing the command for me via SSH. But that’s for another day.