AppleScript and pages not playing along?

Discussion in 'Mac Programming' started by TheEmpty, Sep 5, 2011.

  1. TheEmpty macrumors member

    Jul 11, 2011
    Today I'm having a mac day, played around with xCode, remembered why I love Ruby and Java and don't like to journey down into lower levels. Then I found AppleScript, which is really nice! So I'm trying to make a script that will package my Java applications for school. I seem to be having a problem when telling pages to open the document.


    set lastName to "SET ME"
    set studentID to "SET ME TOO"
    set projectName to text returned of (display dialog "Project Name" default answer "UniProject")
    set projectNumber to text returned of (display dialog "Project Number" default answer 1)

    setup the tmp directory
    do shell script "rm -fr /tmp/uni-packager"
    do shell script "mkdir /tmp/uni-packager"

    -- copy the Netbean files
    do shell script "cp -r ~/NetBeansProjects/" projectName "/ /tmp/uni-packager/project"

    -- look for pages doc and compile
    set fileLocation to 
    "~/Documents/" projectName ".pages"
    set pdfLocation to "~/Desktop" projectName ".pdf"
    tell application "Pages"
    open file fileLocation
        set product to front document
        save product in pdfLocation
    end tell
    do shell script "mv " pdfLocation " /tmp/uni-packager/"
    -- do shell script "cp ~/Documents"

    -- remove git and mac files
    do shell script "rm -r /tmp/uni-packager/project/.git*"
    do shell script "find /tmp/uni-packager/. -name *.DS_Store -type f -exec rm {} \\;"
    -- compress
    do shell script "zip -r ~/Desktop/" lastName "_" studentID "_project" projectNumber ".zip /tmp/uni-packager/*"
    -- delete temp
    do shell script "rm -rf /tmp/uni-packager"
  2. DESNOS, Sep 12, 2011
    Last edited: Sep 12, 2011

    DESNOS macrumors 6502

    Aug 24, 2011
    First of all, Applescript does not expand "~" when used outside of "do shell script", so you have add:
    set homeFolder to POSIX path of home folder from user domain
    Also, you can't use POSIX paths in regular applescript. You have to replace "open file fileLocation" with "open POSIX file fileLocation", after you replace the "~" with the "homeFolder" variable up there. You're missing a "/" in pdflocation too. You also have to put the "rm" in a try block incase the folder doesn't exist already, which will be true by default. This code has so many problems...
  3. TheEmpty, Sep 14, 2011
    Last edited: Sep 14, 2011

    TheEmpty thread starter macrumors member

    Jul 11, 2011
    Thanks for the POSIX stuff, it's actually harder for me to do it in this then in something like C :p

    rm doesn't need a try block because of the options ;)

    still having a bit of trouble, think I'll just end up doing it by hand.
    just ./ it to show it's there

Share This Page