EzDevInfo.com

automator interview questions

Top automator frequently asked interview questions

Automatic PDF renaming based on title

I have thousands of scientific PDFs that i need to rename, many do not have metadata. I would like to be able to create an automator action that could open a folder then open each PDF, copy the title and rename the document and save in a new folder. I have spent hours try to figure this out so I would greatly appreciate nay help. I have Apple G5 2.26Gz quad running os10.6 Thanks!


Source: (StackOverflow)

OS X Lion Inverted Scrolling Automation Shortcut

As everyone will know (who has Mac OS X Lion), by default, scrolling is inverted to make it a bit like the iPhone.

Problem: There is no way to have "normal scrolling" for a USB mouse, and "natural/inverted" scrolling for the trackpad. The setting (even though it is listed in both the mouse and trackpad settings) applies to both.

Question: Could someone, who is experienced with Automator or AppleScipting, please give me a few tips on how to make a shortcut that can toggle the inverted setting? I need this as when I'm at home, I have my Mac Book Air plugged to my Keyboard, Mouse and Monitor, and I'd like a quick way to change this setting


Source: (StackOverflow)

Advertisements

Automator workflow save as

(first time automator user)

I created an Automator workflow (Folder Action) that watches a certain folder for certain file types and moves them to another folder.. I've tested it via Step and Run and it works fine. How do I save this as an app, or at least run on startup?

Thanks..


Source: (StackOverflow)

How do I set up a OSX service to delete the first page of a PDF?

I frequently receive PDF files where the first page is either empty or is just a cover page for which I have no use. Can you suggest a quick and efficient way (Applescript, Service, or ???) for me to delete just that first page and save the file?

If this can be automated via Preview or Adobe Acrobat Professional, that would be most ideal.

Any ideas?


Source: (StackOverflow)

Mass Convert .xls and .xlsx to .txt (Tab Delimited) on a Mac

I have about 150 .xls and .xlsx files that I need converting into tab-delimited. I tried using automator, but I was only able to do it one-by-one. It's definitely faster than opening up each one individually, though. I have very little scripting knowledge, so I would appreciate a way to do this as painlessly as possible.


Source: (StackOverflow)

Is it possible to run an Automator workflow when a USB device is connected?

I would like to run an Automator workflow every time I connect a certain thumbdrive to my OS X Snow Leopard system. This workflow will copy certain files from my hard drive onto the thumb drive. I have the workflow part figured out, but I don't know how to trigger it. Ideally, I wouldn't need to do anything; it would run as soon as the drive is mounted.

Is this possible? Am I approaching this from the wrong angle?

The solution only really needs to work on Snow Leopard.

Thanks!


Source: (StackOverflow)

Automating telnet login and commands on a Mac

Currently I do something like this:

telnet 192.168.0.3 23

username

password

cd /dir/

programname -s -g dosomething

I want to do this with one step, the coolest would be to compile a program for this using Automator, but i have no idea how to do that.
"shell script" in Automator fails at telnet 192.168.0.3 23 saying "connection refused" of course: I had no chance to type in password and so on.

Any ideas?


Source: (StackOverflow)

Create bash script to open URL in Mac OS X

I want to OS X to intelligently open git URLs by first trying to open their repo page on GitHub, and then falling back to something like GitBox.app.

I found this question extremely helpful, and I created an Automator app to wrap a bash script (which does all of the intelligent stuff), and used RCDefaultApp to set OS X to use my automator app to open git:// URLs.

This didn't work, so I tried some debugging. I set my bash script to output its arguments to /tmp/output.txt, and it turns out that the script isn't getting any command line arguments. If I set OS X to use this same automator app as the default app for *.txt files, the bash script correctly gets the path of the file as the first argument, but it doesn't work with URLs. Any idea how to get this to work?

Also, I'm running 10.7.

Edit: Here's a snapshot of the Automator app: Automator app

And here's the text of that simple bash script (not what I would actually use to open the git:// URLs, but it demonstrates the lack of arguments:

rm -f /tmp/output.txt
echo $0 >> /tmp/output.txt
echo $* >> /tmp/output.txt

And the only output I get in /tmp/output.txt is:

-

Source: (StackOverflow)

OS X (Unix) shell command: possible to get last opened date of file?

when you use the following command

find /Users/someUser/someFolder/* -type f -mtime +90

you'll get all the files that have a modification date that is bigger than 90 days. If you open however the file properties in the Finder on OS X for instance there is also a "Last opened" date. Is there a possibility to get all files with a last opened date bigger some treshold like the example above?? Sadly there's no "-otime" :)

Also on Automator you there's no filter for the last open time but just for modified time and created time...

Thanks a lot


Source: (StackOverflow)

What is the best way to make Calculate SHA1 as a context menu option in Mac OS X?

In order to calculate the SHA1 checksum of a downloaded file, I could type

/usr/bin/openssl sha1

in Terminal and then drag there the file which I want check. To make it simpler, one could enable a Context Menu item for this action.

What is the best way to create such item in Mac OS X 10.6? A detailed answer is appreciated, because I don't have good experience with AppleScript, etc.


Step by step

  1. Open Automator
  2. Create new service
  3. Choose to receive selected Files and Folders in Finder
  4. Add action Run Shell Script where your bash command is /usr/bin/openssl sha1 "$@" and you pass input as arguments

How can I get the output? Preferably in a Growl pop-up or a message window/dialog.


Source: (StackOverflow)

Mac OS: How can I launch the iTerm terminal, with a specific profile, from Automator or AppleScript?

I'm trying to assign a global keyboard shortcut that will launch a new window of iTerm, with a specific profile. (I managed to do this to launch a new Chrome window with Automator and AppleScript, but this is proving more difficult)

This would be equivalent to activating iTerm, and in the top menu select Profiles -> "my profile", with "alt" or "option" pressed, so it'll open in a new window, not a new tab in the current window.

Any ideas how to do this with either Automator or AppleScript?

In case it's relevant, I have Mac OS Mountain Lion

(Sorry if this is an absolute noob question, I just moved from Windows to Mac, and I'm trying to optimize the things I do all the time)

Thank you!


Source: (StackOverflow)

How do I parse file paths separated by a space in a string?

Background: I am working in Automator on a wrapper to a command line utility. I need a way to separate an arbitrary number of file paths delimited by a single space from a single string, so that I may remove all but the first file path to pass to the program.

Example input string:

/Users/bobby/diddy dum/ding.mp4 /Users/jimmy/gone mia/come back jimmy.mp3 ...

Desired output:

/Users/bobby/diddy dum/ding.mp4

Part of the problem is the inflexibility on the Automator end of things. I'm using an Automator action which returns unescaped POSIX filepaths delimited by a space (or comma). This is unfortunate because: 1. I cannot ensure file/folder names will not contain either a space or comma, and 2. the only inadmissible character in Mac OS X filenames (as far as I can tell) is :. There are options which allow me to enclose the file paths in double or single quotes, or angle brackets. The program itself accepts the argument of the aforementioned input string, so there must be a way of separating the paths. I just do not have a keen enough eye to see how to do it with sed or awk.

At first I thought I'll just use sed to replace every [space]/ with [newline]/ and then trim all but the first line, but that leaves the loophole open for folders whose names end with a space. If I use the comma delimiter, the same happens, just for a comma instead. If I encapsulate in double or single quotation marks, I am opening another can of worms for filenames with those characters.

The image/link is the relevant part of my Automator workflow.

-- UPDATE --

I was able to achieve what I wanted in a rather roundabout way. It's hardly elegant but here is working generalized code:

path="/Users/bobby/diddy dum/ding.mp4 /Users/jimmy/gone mia/come back jimmy.mp3"

# using colon because it's an inadmissible Mac OS X
# filename character, perfect for separating
# also, unlike [space], multiple colons do not collapse
IFS=:

# replace all spaces with colons
colpath=$(echo "$path" | sed 's/ /:/g')

# place words from colon-ized file path into array
# e.g. three spaces -> three colons -> two empty words
j=1
for word in $colpath
do
    filearray[$j]="$word"
    j=$j+1
done

# reconstruct file path word by word
# after each addition, check file existence
# if non-existent, re-add lost [space] and continue until found
name=""
for seg in "${filearray[@]}"
do
    name="$name$seg"
        if [[ -f "$name" ]]
        then
            echo "$name"
            break
        fi
    name="$name "
done

All this trouble because the default IFS doesn't count "emptiness" between the spaces as words, but rather collapses them all.


Source: (StackOverflow)

Mac Automator Save to Current Directory

I am creating a basic Automator service so that I can select a group of images and resize them for our CMS. The thing that keeps messing me up is that I can't find a good way to make the resized images save to the directory where the current images are. I want to keep them grouped and not have to save them to the Desktop or some other arbitrary folder. Does anyone know of a good way to tell an automator service to save to the current directory? Thanks.


Source: (StackOverflow)

How do I run an Automator action, shell script or AppleScript on startup in OS X?

I know you can run applications on startup on a Mac, but can you run an Automator action, a Service, a shell script, or an AppleScript on startup instead?

I also know you can save all of these as an application, but I don't want it opening in the dock.


Source: (StackOverflow)

Remove All Illegal Characters from All Filenames in a Given Folder and subfolders

I Know this was was basically answered and the automator with the shell script (Sanitize Filenames) works great, but I need it to also do all subfolders as well. And if possible trim the file name down to 50 characters while retaining the file extension. I had found a line of bash code that truncated the file but it also stripped the extension and that does not work well when transferring these files from Macs to Windows.

The script as it stands is this

for f in "$1"/*; do
dir=$(dirname "$f")
file=$(basename "$f")
mv "$f" "${dir}/${file//[[:cntrl:]\\\/:*?\"<>|]/_}" 
done 

I am not opposed to using applescript in automator to complete this task.


Source: (StackOverflow)