14 Replies Latest reply on Oct 29, 2014 1:35 AM by Kit Greer

    Yosemite Applescript and ID CC '14

    Kit Greer

      I'm no scripter, so it took me a good full day to work out how to get InDesign CS6 to open a doc, ask for a .csv, merge the doc, save it as a PDF, close both the new merged doc and template, rename the PDF with todays date and time, then move the PDF to an FTP, all at the click of an Applescript. Really chuffed with myself.

       

      Now everything has been upgraded to Yosemite and ID CC 2014, only half at best works. The language seems to have changed from the 'plain English' of Applescript, to Java (I think) which I know even less about, and it all seems to look a lot different after being converted to 10.10. After tweaking the doc best I can, it opens, asks, merges then gets stuck on exporting to PDF. I can't work this bit out. Everything else seems to be ok so far..

       

      Does anyone know the secret to exporting without options? (also the 2 'close' commands are closing the template doc and the created merge doc without saving)

       

      It was;

       

      tell active document

      export format PDF type to "file path...." without showing options

      tell myDocument to close saving no

      close saving no

       

      and now it's;

       

      tell «class pacd»

        «event K2  expt» without «class imot» given «class exft»:«constant eXftt_PD», «class kfil»:"Megatron:Users:kit:Desktop:Test:date.pdf"

        tell myDocument to «event CoReclos» given «class svop»:no

        «event CoReclos» given «class svop»:no

        • 1. Re: Yosemite Applescript and ID CC '14
          rob day Adobe Community Professional & MVP

          The application exports a PDF not the document, so your tell has to be to ID not the document. This should work:

           

          tell application "Adobe InDesign CC2014"

              --choose pdf destination

              set myFolder to (choose folder with prompt "Please select an Export Destination") as string

           

              tell active document

                  --the document name for saving pdf

                  set myFileName to name

                  set thePath to (myFolder & myFileName & ".pdf")

                  --or

                  --set thePath to "Megatron:Users:kit:Desktop:Test:date.pdf"

                  --application exports not the document

                  tell application "Adobe InDesign CC2014"

                      export active document format PDF type to thePath

                  end tell

                  close saving no

              end tell

          end tell

          • 2. Re: Yosemite Applescript and ID CC '14
            Kit Greer Level 1

            Thanks Rob.

             

            InDesign is already active in an earlier part of the script, as it's performing the mail merge. The script then saves the PDF directly after the merge has been completed.

             

            I copied in the suggestion you made.

             

            For some reason it won't allow 'active document' any more, it's 'page' (don't know why) that seems to work in the first line, but not in the export command, nor 'active document'. It says; "Expected end of line, etc. but found identifier." regardless of what handle I put. It says that error in the first line too, but it doesn't if it's 'page'

             

            I just ran the script after disabling the export option line, just to see what it'd do, and it stopped at the first line with 'page' and said "The variable page is not defined.". I just can't figure out how to tell it to be working on the active/front document.

            • 3. Re: Yosemite Applescript and ID CC '14
              rob day Adobe Community Professional & MVP

              Post the entire script

              • 4. Re: Yosemite Applescript and ID CC '14
                Kit Greer Level 1

                This is the script that worked flawlessly in Mavericks. I even sorted out not having to ask for the data source, but I've removed that bit for now. I'm also just focusing on saving the PDF, you'll notice later in the script about renaming the PDF and moving it. This part still works as expected, and the language hasn't been converted/changed in any way.

                 

                Mavericks Script.jpg

                 

                Then it was moved on to a Mac with Yosemite and ID CC 2014. Opened without touching anything, starts replacing commands with this <<event >> stuff. Is that Java? It opens the file, asks for the data, merges the doc, then stops.

                 

                tell application "Adobe InDesign CC 2014"

                  set myDocument to open "Megatron:Users:kit:Desktop:iMoved:User Letter.indd"

                  set myDataMerge to «class cdmr» 1 of myDocument

                  set myDataSource to choose file without invisibles

                 

                  «event K2PFedms» of myDataMerge given «class pdsf»:myDataSource

                  «event K2PFedmm» myDataMerge

                  tell «class pacd»

                  «event K2  expt» without «class imot» given «class exft»:«constant eXftt_PD», «class kfil»:"Megatron:Users:kit:Desktop:Test:date.pdf"

                  tell myDocument to «event CoReclos» given «class svop»:no

                  «event CoReclos» given «class svop»:no

                  end tell

                  end tell

                 

                and with your tweaks as above;

                 

                tell application "Adobe InDesign CC 2014"

                  set myDocument to open "Megatron:Users:kit:Desktop:iMoved:User Letter.indd"

                  set myDataMerge to «class cdmr» 1 of myDocument

                  set myDataSource to choose file without invisibles

                 

                  «event K2PFedms» of myDataMerge given «class pdsf»:myDataSource

                  «event K2PFedmm» myDataMerge

                  tell page

                  set myFileName to name

                  set thePath to "Megatron:Users:kit:Desktop:Test:date.pdf"

                  --application exports not the document

                  --          export active document format PDF type to thePath

                  close saving no

                  end tell

                  end tell




                • 5. Re: Yosemite Applescript and ID CC '14
                  rob day Adobe Community Professional & MVP

                  You are opening a document in the first line and that document becomes the active doc. So the tell for the export can be either the active document or the myDocument variable—they're the same. Tell page doesn't work because ID doesn't know what that means (what page? what document?)

                   

                  tell application "Adobe InDesign CC 2014"

                      set myDocument to open "Megatron:Users:kit:Desktop:iMoved:User Letter.indd"

                      set myDataMerge to data merge 1 of myDocument

                      set myDataSource to choose file without invisibles

                      select data source of myDataMerge data source file myDataSource

                      merge records myDataMerge

                     

                      tell myDocument

                          export format PDF type to "Megatron:Users:kit:Desktop:Test:date.pdf"

                          close saving no

                      end tell

                  end tell

                  • 6. Re: Yosemite Applescript and ID CC '14
                    Kit Greer Level 1

                    But doing the mail merge, the new document it creates becomes the active document, not the original one.

                     

                    Pasting that script still throws strange errors that weren't in Mavericks. Don't know why Apple messed around with scripts! grrrrr...

                     

                    Errors now; the number '1' in the 3rd line, compiling the script says; Expected end of line, etc. but found number.

                    Deleting the number, then moves on to the word 'data' in the 5th line; Expected end of line, etc. but found class name.

                    Deleting this just bowls on to the next word. Hitting enter each time to drop it a line works, in that it accepts it, but running the script doesn't work

                    • 7. Re: Yosemite Applescript and ID CC '14
                      rob day Adobe Community Professional & MVP

                      This is the script that worked flawlessly in Mavericks.

                      Also, your capture of the working script is targeting CC not CC 2014. You could try creating a folder inside of your CC 2014 scripts folder named "Version 9.0 Scripts" and put the working original there and run from inside of ID. The folder name is case sensitive—name needs to be exact

                      • 8. Re: Yosemite Applescript and ID CC '14
                        rob day Adobe Community Professional & MVP

                        Your script is only opening one InDesign doc. The data file (myDataSource) is merged into the front document—it isn't making a new doc.

                        I haven't seen any problems with AS in Yosemite yet.

                        Here it is annotated:

                         

                        tell application "Adobe InDesign CS6"

                          

                            --this becomes the active document

                            set myDocument to open "Megatron:Users:kit:Desktop:iMoved:User Letter.indd"

                          

                            --myDocument's data merge object

                            set myDataMerge to data merge 1 of myDocument

                          

                            --path to a chosen text file with data

                            set myDataSource to choose file without invisibles

                          

                            --use the open data file as the source

                            select data source of myDataMerge data source file myDataSource

                          

                            --merge the records, myDataMerge is part of the open doc (myDocument)

                            merge records myDataMerge

                          

                            --the open document, could also be tell active document

                            tell myDocument

                              

                                export format PDF type to "Megatron:Users:kit:Desktop:Test:date.pdf"

                              

                                close saving no

                              

                            end tell

                        end tell

                        • 9. Re: Yosemite Applescript and ID CC '14
                          Kit Greer Level 1

                          Rob Day wrote:

                           

                          This is the script that worked flawlessly in Mavericks.

                          Also, your capture of the working script is targeting CC not CC 2014. You could try creating a folder inside of your CC 2014 scripts folder named "Version 9.0 Scripts" and put the working original there and run from inside of ID. The folder name is case sensitive—name needs to be exact

                          Like I said, it was written on a Mac running Mavericks and CC, then moved on to a Mac running Yosemite and CC 2014 (with updated file/folder paths)

                           

                          I've opened other scripts unrelated to this, to have them be modified too. The new version of AppleScript in Yosemite appears to be updated from Mavericks, but it's not translating properly. I've not worked out how/why it's doing what it does yet.

                          • 10. Re: Yosemite Applescript and ID CC '14
                            Kit Greer Level 1

                            Rob Day wrote:

                             

                            Your script is only opening one InDesign doc. The data file (myDataSource) is merged into the front document—it isn't making a new doc.

                            I haven't seen any problems with AS in Yosemite yet.

                            Here it is annotated:

                             

                            tell application "Adobe InDesign CS6"

                             

                                --this becomes the active document

                                set myDocument to open "Megatron:Users:kit:Desktop:iMoved:User Letter.indd"

                             

                                --myDocument's data merge object

                                set myDataMerge to data merge 1 of myDocument

                             

                                --path to a chosen text file with data

                                set myDataSource to choose file without invisibles

                             

                                --use the open data file as the source

                                select data source of myDataMerge data source file myDataSource

                             

                                --merge the records, myDataMerge is part of the open doc (myDocument)

                                merge records myDataMerge

                             

                                --the open document, could also be tell active document

                                tell myDocument

                                 

                                    export format PDF type to "Megatron:Users:kit:Desktop:Test:date.pdf"

                                 

                                    close saving no

                                 

                                end tell

                            end tell

                            I understand all of this, but when you mail merge a doc, it creates a new document which becomes the active new doc, and the originally opened file is then behind. The script falls over at 'data merge 1 of myDocument', it doesn't understand the '1' and then falls again (if you delete the 1) at 'select data source of myDataMerge data source file myDataSource', it doesn't understand the 'source' so remove that, it then questions the 'file', remove that it then questions the 'data'. It's just not working.

                             

                            I can get it to open, ask for the data, merge the doc, but then it falls at exporting/saving as a PDF. I'm only focusing on this now. I don't fully understand why it's working the way it is, but it's working. So now it's just getting it to export and close both docs without saving. This is the only 2 parts of the script not working. The rest is now irrelevant as it works (somehow!)

                            • 11. Re: Yosemite Applescript and ID CC '14
                              rob day Adobe Community Professional & MVP

                              I understand all of this, but when you mail merge a doc, it creates a new document which becomes the active new doc, and the originally opened file is then behind

                              Then just change the tell to active document. Something's wrong with your Script Editor are you running the current version Version 2.7 (176)?

                               

                              Also try deleting the application name in the first tell so you are forced to find CC2014 when you compile, you shouldn't be seeing the class references:

                               

                              tell application ""

                                  set myDocument to active document

                              end tell

                               

                              I made a sample data file and it works for me.

                               

                              Screen Shot 2014-10-28 at 8.03.41 PM.png

                              • 12. Re: Yosemite Applescript and ID CC '14
                                rob day Adobe Community Professional & MVP

                                Looking at your screen capture in #4 I can see you aren't running Yosemite's Script Editor. It should have Yosemite's interface like this:

                                 

                                Screen Shot 2014-10-28 at 8.14.50 PM.png

                                • 13. Re: Yosemite Applescript and ID CC '14
                                  Kit Greer Level 1

                                  I really don't know what's wrong with it. May be it needs reinstalling then..

                                  If you read my post, I mention that the screenshot is Mavericks. If it was Yosemite, then I wouldn't be having issues, it'd work. And yes, it's 2.7 (176). I'm wondering if it's something to do with that, or the AppleScript library/? of InDesign CC 2014.

                                   

                                  Thanks for your patience and trying anyway. I tried reinstalling CC, but it didn't change anything. Yosemite shots. Original untouched script, just opened, and script run, but after merging the document, it stops here

                                   

                                  Screen Shot 2014-10-29 at 20.11.03.pngScreen Shot 2014-10-29 at 20.24.26.png

                                  • 14. Re: Yosemite Applescript and ID CC '14
                                    Kit Greer Level 1

                                    Rob Day wrote:

                                     

                                    Looking at your screen capture in #4 I can see you aren't running Yosemite's Script Editor. It should have Yosemite's interface like this:

                                     

                                    Screen Shot 2014-10-28 at 8.14.50 PM.png

                                    I don't get how yours is working! I just had a friend open the script on his Mac with 10.10, and send me back a screenshot, and it was the same on his as it is on mine too! Even writing a fresh new script with this text you show, does not work.. Just don't get it

                                     

                                    ___ Edit ___

                                    Just switched everything off, restarted, opened up a fresh script, typed in this lot, and it works now!!

                                    I've then rebuilt around this script, all the rest of the function, and PRESTO!!!! It works again!!

                                     

                                    Thanks for your help!

                                     

                                    Screen Shot 2014-10-29 at 21.34.39.png