PDA

View Full Version : AppleScript...am I just dumb?




tbone82
Aug 5, 2006, 02:44 PM
I have never really programmed anything before other than a TI-83 calculator in high school years ago... but I got my Mac in January, and I was curious to try out AppleScripts, since the OS X overview implied it was so easy.
All I want to do is tell it to print a bunch of pdf files without printing the first page of any of them (pages 2-?). I decided to try it out by just opening one of the files. Preview wasn't in the list of programs to use AppleScripts with, so I decided to use Safari. I made the following script:

tell application "Safari"
open file "Macintosh HD/Excerpts/Wagner/Lohengrin_prelude.pdf"
end tell

This was following what little basic information I could find in AppleScript help and online at <http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.fd.html>

However, when I try to run this script, Safari tells me that there is no file at that address!

Did I do something wrong?

Thanks

Tommy



HiRez
Aug 5, 2006, 02:55 PM
Well I'll ask the obvious first...are you absolutely sure the file and path are spelled/typed correctly? For example, you really should not have a folder named "Excerpts" directly under your root in OS X. If you do, something is wrong. It should look something more like:

/Volumes/Macintosh HD/Users/<your user name here>/Documents/Excerpts/Wagner/Lohengrin_prelude.pdf

or

/Users/<your user name here>/Documents/Excerpts/Wagner/Lohengrin_prelude.pdf

(You may not need the first two components if you only have one hard drive). One way to get an accurate full path is to open Terminal, drag the file into it, and select and copy the path that appears.

EDIT: I think I see what is going on here: the article you linked dates from 1999, so it was probably written for OS 9 or maybe a very, very early version of OS X. You need to find a more modern one (sorry, I don't do much AppleScript so I can't help you there, but Google it for starters and always check the dates on online articles when you're looking to learn something).

tbone82
Aug 5, 2006, 03:03 PM
Actually, I dragged the "Excerpts" folder directly in Macintosh HD myself to uncomplicate things when typing it in the script...it was in my Desktop before.

Thanks for the reply

HexMonkey
Aug 5, 2006, 07:17 PM
Changing the slashes to colons should fix it.

ie
tell application "Safari"
open file "Macintosh HD:Excerpts:Wagner:Lohengrin_prelude.pdf"
end tell

tbone82
Aug 6, 2006, 08:13 AM
Changing the slashes to colons should fix it.

ie
tell application "Safari"
open file "Macintosh HD:Excerpts:Wagner:Lohengrin_prelude.pdf"
end tell

Thanks HexMonkey...that worked. Now...the question is, how do I tell it to print a file omitting page 1? Is there a way to do this without specifying the ending page?

Thanks all

Sayer
Aug 6, 2006, 10:56 AM
You haven't mentioned which Mac OS X version you have, but this Automator workflow runs on Mac OS X 10.4 and up.

Basically it does everything you want, printing PDFs starting at page 2. And it doesn't use AppleScript at all.

The folder to get PDFs from is "PDF To Print" and the temporary storage area for printing is set to the Desktop, but you can easily change it.

This will leave page 1 from the PDFs on the Desktop/in the temp folder, but hey you can easily find and manually trash them after processing. Or make an AppleScript to do it.

Sayer
Aug 6, 2006, 03:11 PM
Here's a better version. This one extracts the pages as separate PDFs and not images, and it should keep the pagination straight.

SC68Cal
Aug 6, 2006, 04:30 PM
And it doesn't use AppleScript at all.


Not to be a nit picker, but I believe Automator is a GUI and User Friendly version of Applescript, that allows people with absolutely no skills with scripting languages to do scriptable tasks.

The penalty is that Automator workflows are bloated compared to their applescript equivalents.