Renaming bookmarks in a pdf

Discussion in 'Mac Programming' started by fightforthefutu, Nov 21, 2014.

  1. fightforthefutu, Nov 21, 2014
    Last edited: Nov 21, 2014

    fightforthefutu macrumors newbie

    Joined:
    Nov 12, 2014
    #1
    Greetings,

    I have a tiresome task of renaming hundreds of bookmarks in nearly fifty pdf books. An applescript seems like the best solution, but my scripting has not produced results. I'm using OSX 10.8.5 on a Mac mini.

    Code:
    tell application "Adobe Acrobat Pro"
    	try
    		set (every text of every bookmark of document 1 whose it = "560-VAA") to "EPCA_April_14"
    	end try
    end tell
    
    What's going wrong with it?

    I know the script can handle bookmarks. A script I found online works well when deleting them.

    Code:
    tell application "Adobe Acrobat Pro"
        delete bookmarks of document 1
    end tell
    
    A slight modification to the first script resulted in bizarre consequences:

    Code:
    tell application "Adobe Acrobat Pro"
    	
    	set name of every bookmark to text
    	try
    		set (text where it is "560-AAA") to "EPCA_April_14"
    	end try
    end tell
    The consequence with this is, all of the hundreds of bookmarks are renamed "ctxt". So that's not progress, but its generally in the right direction! Any further observations or aid would be greatly appreciated. Thanks!
     
  2. fightforthefutu, Nov 24, 2014
    Last edited: Nov 24, 2014

    fightforthefutu thread starter macrumors newbie

    Joined:
    Nov 12, 2014
    #2
    Still stuck on renaming bookmarks

    Hello, hope everyone had a good weekend!

    I'm back to playing with an applescript to rename bookmarks. After Friday's effort, I discovered that the line "set name of every bookmark to text" gave me "ctxt" because that is the literal name for "text". Interesting. Unhelpful, but interesting.

    Now I have been able to rename bookmarks based on their ordered number. So,

    Code:
    tell application "Adobe Acrobat Pro"
    	try
    	set (name of bookmark 1) to "Cover"
    		set (name of bookmark 2) to "Title Page, Copyright"
    	end try
    end tell
    

    This syntax is not particularly helpful as some books have more bookmarks than others. It would be much better to change the names of the bookmarks themselves. So, I finally put together the right combination of little words, and Presto!

    Code:
    tell application "Adobe Acrobat Pro"
    	try
    		set name of every bookmark whose name contains "0001-AAA" to "Cover"
    		set name of every bookmark whose name contains "0002-AAA" to "Title Page, Copyright"
    		set name of every bookmark whose name contains "0003-AAA" to "Index"
    	end try
    end tell
    Yes, its all childishly simple. But then, I'm a kid at heart, and a programmer I'm not.
     

Share This Page