AppleScript...am I just dumb?

Discussion in 'Mac Programming' started by tbone82, Aug 5, 2006.

  1. macrumors newbie

    Joined:
    Aug 5, 2006
    #1
    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
     
  2. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    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).
     
  3. thread starter macrumors newbie

    Joined:
    Aug 5, 2006
    #3
    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
     
  4. Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #4
    Changing the slashes to colons should fix it.

    ie
    Code:
    tell application "Safari"
    	open file "Macintosh HD:Excerpts:Wagner:Lohengrin_prelude.pdf"
    end tell
     
  5. thread starter macrumors newbie

    Joined:
    Aug 5, 2006
    #5
    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
     
  6. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #6
    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.
     
  7. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #7
    Here's a better version. This one extracts the pages as separate PDFs and not images, and it should keep the pagination straight.
     

    Attached Files:

  8. macrumors 68000

    Joined:
    Feb 23, 2006
    #8
    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.
     

Share This Page