Numbers to PDF folder action?

Discussion in 'Mac Programming' started by The JTizzle, Sep 15, 2016.

  1. The JTizzle macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine
    #1
    I'm super desperate and hoping someone can help me. I need a folder action so when I drop a numbers file into the folder it converts it to a PDF and junks the numbers doc. Can anyone share or make me this? Been trying to make one myself but just can;'t get it to work :(
     
  2. mikew99, Sep 15, 2016
    Last edited: Sep 15, 2016

    mikew99 macrumors newbie

    Joined:
    Sep 15, 2016
    #2
    This seems to work, but will export the PDF to your desktop.

    on adding folder items to this_folder after receiving added_items
    repeat with this_file in added_items
    tell application "Finder"
    set theInfo to properties of this_file
    set theName to name of theInfo
    set theName to (characters 1 through -9) of theName as text
    set thePath to desktop as string
    end tell

    tell application "Numbers"
    activate
    open this_file
    set thisDoc to document 1
    export thisDoc to file (thePath & theName & ".pdf" as string) as PDF
    quit
    end tell


    tell application "Finder"
    delete this_file
    end tell

    end repeat
    end adding folder items to
     
  3. The JTizzle, Sep 16, 2016
    Last edited: Sep 16, 2016

    The JTizzle thread starter macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine
    #3

    Ok tried it and this is almost perfect, can you explain what I can change to edit the final location of the PDF so stays in the folder that with the folder action? (which is a dropbox folder)
     
  4. mikew99 macrumors newbie

    Joined:
    Sep 15, 2016
    #4
    You could make a folder on your desktop and have it exported to that location. For instance, you could create a folder named "Exported PDF" that resides on your desktop. Then what you would want to do is change the path to direct to that folder. In my example, thePath is the desktop folder. You could change that one line in the script to:

    set thePath to folder "Exported PDF" of desktop as string
     
  5. The JTizzle thread starter macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine
    #5
    How would you write a path to something other than the desktop? such as ~/Dropbox/Folder 1 ? I understand the concept, just can't get it to work with the proper edit
     
  6. mikew99 macrumors newbie

    Joined:
    Sep 15, 2016
    #6
    One thing you could do is open Script Editor and run this:

    tell application "Finder"
    set theFolder to choose folder
    end tell

    Whatever the result is, just copy that and set thePath to your result.
     
  7. The JTizzle thread starter macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine
    #7
    Oh thats perfect, I got it. THANKS A TON!!!!!!!!!!!!!!!!! If you ever need a design favor hit me up, I owe you one man!
     
  8. mikew99 macrumors newbie

    Joined:
    Sep 15, 2016
    #8
    You'd kind of end up with the line looking something like this:

    set thePath to folder "Macintosh HD:Users:User:Dropbox:Folder 1:" as string
    --- Post Merged, Sep 16, 2016 ---
    You're welcome, sir. Have a good one.
     
  9. The JTizzle thread starter macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine
    #9
    sorry one last question, will this overwrite a old PDF file if a new one is created with the same name? Or do I need to add something to get that to work?
     
  10. mikew99 macrumors newbie

    Joined:
    Sep 15, 2016
    #10
    Yes, I think that it will overwrite the existing file in that Dropbox folder. Let me test it out and I will let you know.
    --- Post Merged, Sep 16, 2016 ---
    Are your numbers documents NOT going to have unique names? If each numbers document has a unique name, then it won't be an issue.
     
  11. The JTizzle thread starter macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine
    #11
    Sorry was a busy day. The overwrite works flawlessly, tested it a few times. The one last issue I seem to have is after testing is I put the numbers files in the folder, it does the conversion, junks the numbers but then tries to run the conversion again on the newly created PDF since I am using the conversion folder as the destination folder. Is there something I can add to make it ignore PDF file types? We lock that in and its flawless!
     
  12. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #12
  13. The JTizzle thread starter macrumors 6502

    The JTizzle

    Joined:
    Jun 14, 2009
    Location:
    Maine

Share This Page