Hello -
I made a small script to combine/merge to .PDF into 1 file.
It works like a charm as long as I late it run as a “script”.
But when I run it as an “application” I get the following error message:
“Can’t make document “test_XXX.pdf” of application “Adobe Acrobat Pro” into the expected type.”
Could anyone tell me why?
Thank you very much, have a nice day.
It would be useful to know which instruction gives this error message.
Yvan KOENIG (VALLAURIS, France) mardi 17 février 2015 16:50:04
Do you run the application in the same bit mode as script editor?
Hello -
¢ Yvan, how could I know, because the script gives an error in the middle of the process.
Would you like that I upload the whole script?
¢ DJ Bazzie Wazzie, it’s seems that I have NO possibility to change it (to play with it),
when I made a “apple - I” on the .app
The only thing I can play with is the “Prevent App Nap”.
NB. I working with Mac OS X 10.9.5 (thus NO Rosetta anymore, NO possibility to work in 32bits mode)
Hello -
Could it be a question of “Username | Password”?
Not needed when working directly with the script, but mandatory when exported as an application?
We are working directly on a server.
Thank you,
You may insert some instructions like :
some code
Say “I am at point 1”
some code
Say “I am at point 2”
some code
.
So you will know which is the late say executed before the error.
Add some more say instructions after the late executed one.
With some attempts you will know which is the failing instruction.
You may post the script but don’t assume that I will find the error.
I don’t own Acrobat Pro so I’m unaware of its requirements and I will be unable to use the say trick to identify the wrongdoer.
Yvan KOENIG (VALLAURIS, France) mercredi 18 février 2015 11:46:38
Hello Yvan -
Seems that 1st error is in 3rd part of the script → “open (myVar as alias)”
Here is already the code:
set myApp to "Adobe Acrobat Pro"
(* Select/choose the FOLDER en d the .PDF *)
set source_folder to choose folder with prompt " 1. ✖︎ Please select the FOLDER containing the PDFs that will combined "
set Insert_File to choose file with prompt " 2. ✖︎ Please select the PDF to be Added/Combined "
set Combined_Folder to ((source_folder as text) & "Combined PDF:")
tell application "Finder"
set Insert_FileName to name of Insert_File
set file_list to every file of source_folder whose name ends with ".pdf"
end tell
---------------------------------------------------------------------------------------------
tell application myApp
reopen
activate
open Insert_File as alias
set Insert_Document to document Insert_FileName
end tell
---------------------------------------------------------------------------------------------
set original_name to text 1 thru -8 of Insert_FileName & "_HR.pdf"
if original_name contains "_HR" then
set new_file_name to text 1 thru -8 of original_name & "_HRLR_Combined.pdf"
tell application "Adobe Acrobat Pro"
set myVar to (source_folder as text) & original_name as text
open (myVar as alias) -- Seems that 1st error is here.
set original_Document to document original_name
set lastPage to count of pages of original_Document
tell original_Document to insert pages after lastPage from Insert_Document starting with 1 number of pages 1
set logpath2 to source_folder as text
set logfile2 to logpath2 & new_file_name
delay 2 -- Just to be sure that the document is "present" on screen.
---------------------------------------------------------------------------------------------
(* Change de default appearance of the new .PDF file *)
tell application "System Events"
tell process "AdobeAcrobat"
set frontmost to true
tell menu bar 1
tell menu bar item "File"
tell menu "File"
tell menu item "Properties..."
click
end tell
end tell
end tell
end tell
tell item 1 of every tab group of window "Document Properties"
click radio button "Initial View"
tell group "Layout and Magnification"
tell pop up button 1
click
tell menu 1
click menu item "Pages Panel and Page"
end tell
end tell
end tell
end tell
click button "OK" of window "Document Properties"
end tell
end tell
---------------------------------------------------------------------------------------------
delay 1 -- Just to be sure that "Document Properties" window is well closed.
save original_Document to logfile2
close document new_file_name without saving
end tell
end if
tell application myApp
close Insert_Document without saving
end tell
---------------------------------------------------------------------------------------------
(* Ask if the user want to see the bra,d new .PDF file *)
tell application "Finder"
tell process "Finder"
set frontmost to true
display dialog " ✖︎ Open the NEW combined file you just made? " buttons {" ¢ YES ¢ ", " ¢ NO ¢ "} default button 2
if result = {button returned:" ¢ NO ¢ "} then
tell application "Adobe Acrobat Pro"
quit
end tell
else
tell application "Adobe Acrobat Pro"
set frontmost to true
set myVar to (source_folder as text) & new_file_name as text
open (myVar as alias)
end tell
end if
end tell
end tell
When I write : say, I mean say !
It’s a Standard Additions command available on every macintosh.
say – Speak the given text
text – the text to speak, which can include intonation characters
[displaying text] – the text to display in the feedback window (if different). Ignored unless Speech Recognition is on.
[using text] – the voice to speak with. (Default is the system voice.)
[speaking rate number] – the rate of speech in words per minute. Average human speech occurs at a rate of 180 to 220 words per minute. (Default depends on the voice used. If “using” is not given, the system speaking rate is the default.)
[pitch number] – the base pitch frequency, a real number from 0 to 127. Values correspond to MIDI note values, where 60 is equal to middle C. Typical pitches range from around 30 to 40 for a low-pitched male voice to perhaps 55 to 65 for a high-pitched child’s voice.
[modulation number] – the pitch modulation, a real number from 0 to 127. A value of 0 corresponds to a monotone in which all speech is at the base speech pitch. Given a pitch value of 46, a modulation of 2 means the widest range of pitches would be 44 to 48.
[volume number] – the volume, a real number from 0 to 1 (default is the system volume).
[stopping current speech boolean] – stop any current speech before starting (default is false). When false, “say” waits for previous speech commands to complete before beginning to speak.
[waiting until completion boolean] – wait for speech to complete before returning (default is true).
[saving to any] – the alias, file reference or path string of an AIFF file (existing or not) to contain the sound output.
Yvan KOENIG (VALLAURIS, France) mercredi 18 février 2015 15:03:25
I inserted a lot of say instructions.
Try to run this edited version to learn which instruction is the wrongdoer.
set myApp to "Adobe Acrobat Pro"
(* Select/choose the FOLDER en d the .PDF *)
set source_folder to choose folder with prompt " 1. ✖︎ Please select the FOLDER containing the PDFs that will combined "
set Insert_File to choose file with prompt " 2. ✖︎ Please select the PDF to be Added/Combined "
set Combined_Folder to ((source_folder as text) & "Combined PDF:")
tell application "Finder"
set Insert_FileName to name of Insert_File
set file_list to every file of source_folder whose name ends with ".pdf"
end tell
---------------------------------------------------------------------------------------------
tell application myApp
reopen
activate
open Insert_File as alias
set Insert_Document to document Insert_FileName
end tell
---------------------------------------------------------------------------------------------
# Here I am puzzled
# your instruction behave as if it was spelled :
set original_name to (text 1 thru -8 of Insert_FileName) & "_HR.pdf"
# so it will always build something like "xxxxx_HR.pdf"
# and the test about the availability of "_HR" will be always matched.
# Just for see :
# assuming that Insert_FileName is "x098765.pdf"
set original_name to text 1 thru -8 of Insert_FileName & "_HR.pdf"
# original_name is now "x098_HR.pdf"
# if original_name contains "_HR" then # This test was perfectly useless, disabled by YK
# as the string is available we are ALWAYS here
set new_file_name to text 1 thru -8 of original_name & "_HRLR_Combined.pdf"
# new_file_name is "x098_HRLR_Combined.pdf"
# I moved this instruction out of the tell Acrobat block
set logpath2 to source_folder as text # was in the tell original_Document block
set myVar to logpath2 & original_name # Edited according to what we defined above
tell application "Adobe Acrobat Pro"
open (myVar as alias)
set original_Document to document original_name
tell original_Document
tell me to say "I am at point 70"
set lastPage to count of pages # was out of the tell original_Document block
tell me to say "I am at point 71"
insert pages after lastPage from Insert_Document starting with 1 number of pages 1 # THE WRONGDOER
tell me to say "I am at point 72"
end tell
set logfile2 to logpath2 & new_file_name
delay 2 -- Just to be sure that the document is "present" on screen.
---------------------------------------------------------------------------------------------
(* Change de default appearance of the new .PDF file *)
tell application "System Events"
tell process "AdobeAcrobat"
set frontmost to true
tell menu bar 1
tell menu bar item "File"
tell menu "File"
tell menu item "Properties..."
click
end tell
end tell
end tell
end tell
tell item 1 of every tab group of window "Document Properties"
click radio button "Initial View"
tell group "Layout and Magnification"
tell pop up button 1
click
tell menu 1
click menu item "Pages Panel and Page"
end tell
end tell
end tell
end tell
click button "OK" of window "Document Properties"
end tell
end tell
---------------------------------------------------------------------------------------------
delay 1 -- Just to be sure that "Document Properties" window is well closed.
save original_Document to logfile2
close document new_file_name without saving
end tell
# end if # disabled by YK
tell application myApp
close Insert_Document without saving
end tell
---------------------------------------------------------------------------------------------
# YK made some cleaning here
(* Ask if the user want to see the bra,d new .PDF file *)
tell application "SystemUIServer"
display dialog " ✖︎ Open the NEW combined file you just made? " buttons {" ¢ YES ¢ ", " ¢ NO ¢ "} default button 2
end
if result = {button returned:" ¢ NO ¢ "} then
tell application "Adobe Acrobat Pro"
quit
end tell
else
set myVar to (source_folder as text) & new_file_name # Was in the tell Acrobat block ?
tell application "Adobe Acrobat Pro"
set frontmost to true
open (myVar as alias)
end tell
end if
Yvan KOENIG (VALLAURIS, France) mercredi 18 février 2015 15:50:03
Hello Yvan -
Thanks for your reply.
I tried your modified script, again, during the “run” of the script itself, NO problem.
Applescript® went to the whole “process”.
But went I exported the script as an application, this last one blocked at “I am at point 7” (I heard it).
OK
I made some changes in the script above.
May you run it ?
It seems that the wrongdoer is between point 71 and point 72.
Yvan KOENIG (VALLAURIS, France) mercredi 18 février 2015 19:24:12
Good morning Yvan -
Well.
When I export the script as an application, it still “blocked” here:
tell me to say "I am at point 71" -- Application says it, but after it's blocked and I get the error message I wrote in the topic (at the beginning)...
insert pages after lastPage from Insert_Document starting with 1 number of pages 1
tell me to say "I am at point 71"
Hello
OK now we know that the wrongdoer is :
insert pages after lastPage from Insert_Document starting with 1 number of pages 1
I don’t know Acrobat Pro but I am puzzled by this instruction.
If I understand well, it’s supposed to insert the first page of Insert_Document at the very end of original_Document.
If I am right, maybe the code must be edited as :
insert pages after page lastPage from Insert_Document starting with 1 number of pages 1
or
insert pages after last page from Insert_Document starting with 1 number of pages 1
I made some cleaning in the script posted yesterday but I didn’t applied the suggestion written above.
May you post a subset of the event log created when the script is ran from the Editor ?
The log related to this block of instruction :
tell application "Adobe Acrobat Pro"
open (myVar as alias)
set original_Document to document original_name
tell original_Document
tell me to say "I am at point 70"
set lastPage to count of pages # was out of the tell original_Document block
tell me to say "I am at point 71"
insert pages after lastPage from Insert_Document starting with 1 number of pages 1 # THE WRONGDOER
tell me to say "I am at point 72"
end tell
would be fine.
Yvan KOENIG (VALLAURIS, France) jeudi 19 février 2015 11:34:50
Hello Yvan -
Thank you again for you reply.
Now, I tried both “line of code” you asked me to test, but
the exported script (as an application) still block at “point 71” (with the following error msg. for the second line of code “Adobe Acrobat Pro got an error: Invalid first page or page to insert after specified”).
Hereunder is the “EVENT LOG” part you asked for (thus not from the script itself, but well from the exported one as an application:
Euuuh. Ic an’t figure how to copy-paste the “EVENT LOG” since it’s an small application (and thus Applescript Editor isn’t open).
Hereunder is the complete “EVENT LOG” from the script (not the exported one as an application):
tell application “AppleScript Editor”
choose folder with prompt " 1. ✖︎ Please select the FOLDER containing the PDFs that will combined "
→ alias “Macintosh HD:Users:studio_0:Desktop:VPack:”
choose file with prompt " 2. ✖︎ Please select the PDF to be Added/Combined "
→ alias “Macintosh HD:Users:studio_0:Desktop:VPack:TEST_VPack_TEST_LR.pdf”
end tell
tell application “Finder”
get name of alias “Macintosh HD:Users:studio_0:Desktop:VPack:TEST_VPack_TEST_LR.pdf”
→ “TEST_VPack_TEST_LR.pdf”
get every file of alias “Macintosh HD:Users:studio_0:Desktop:VPack:” whose name ends with “.pdf”
→ {document file “TEST_VPack_TEST_HR.pdf” of folder “VPack” of folder “Desktop” of folder “studio_0” of folder “Users” of startup disk, document file “TEST_VPack_TEST_HRLR_Combined.pdf” of folder “VPack” of folder “Desktop” of folder “studio_0” of folder “Users” of startup disk, document file “TEST_VPack_TEST_LR.pdf” of folder “VPack” of folder “Desktop” of folder “studio_0” of folder “Users” of startup disk}
end tell
tell application “Adobe Acrobat Pro”
reopen
→ error number 0
activate
open alias “Macintosh HD:Users:studio_0:Desktop:VPack:TEST_VPack_TEST_LR.pdf”
→ missing value
get document “TEST_VPack_TEST_LR.pdf”
→ document “TEST_VPack_TEST_LR.pdf”
open alias “Macintosh HD:Users:studio_0:Desktop:VPack:TEST_VPack_TEST_HR.pdf”
→ missing value
→ error number 0
get document “TEST_VPack_TEST_HR.pdf”
→ document “TEST_VPack_TEST_HR.pdf”
end tell
tell current application
say “I am at point 70”
end tell
tell application “Adobe Acrobat Pro”
count every page of document “TEST_VPack_TEST_HR.pdf”
→ 1
end tell
tell current application
say “I am at point 71”
end tell
tell application “Adobe Acrobat Pro”
insert pages document “TEST_VPack_TEST_HR.pdf” after 1 from document “TEST_VPack_TEST_LR.pdf” starting with 1 number of pages 1
end tell
tell current application
say “I am at point 72”
say “I am at point 8”
say “I am at point 9”
end tell
tell application “System Events”
set frontmost of process “AdobeAcrobat” to true
end tell
tell current application
say “I am at point 10”
end tell
tell application “System Events”
click menu item “Properties…” of menu “File” of menu bar item “File” of menu bar 1 of process “AdobeAcrobat”
→ menu item “Properties…” of menu “File” of menu bar item “File” of menu bar 1 of application process “AdobeAcrobat”
end tell
tell current application
say “I am at point 20”
end tell
tell application “System Events”
click radio button “Initial View” of item 1 of every tab group of window “Document Properties” of process “AdobeAcrobat”
→ radio button “Initial View” of tab group 1 of window “Document Properties” of application process “AdobeAcrobat”
click pop up button 1 of group “Layout and Magnification” of item 1 of every tab group of window “Document Properties” of process “AdobeAcrobat”
→ pop up button 1 of group “Layout and Magnification” of tab group 1 of window “Document Properties” of application process “AdobeAcrobat”
click menu item “Pages Panel and Page” of menu 1 of pop up button 1 of group “Layout and Magnification” of item 1 of every tab group of window “Document Properties” of process “AdobeAcrobat”
→ menu item “Pages Panel and Page” of menu 1 of pop up button 1 of group “Layout and Magnification” of tab group 1 of window “Document Properties” of application process “AdobeAcrobat”
end tell
tell current application
say “I am at point 30”
end tell
tell application “System Events”
click button “OK” of window “Document Properties” of process “AdobeAcrobat”
→ button “OK” of window “Document Properties” of application process “AdobeAcrobat”
end tell
tell current application
say “I am at point 31”
end tell
tell application “Adobe Acrobat Pro”
save document “TEST_VPack_TEST_HR.pdf” to “Macintosh HD:Users:studio_0:Desktop:VPack:TEST_VPack_TEST_HRLR_Combined.pdf”
end tell
tell current application
say “I am at point 32”
end tell
tell application “Adobe Acrobat Pro”
close document “TEST_VPack_TEST_HRLR_Combined.pdf” saving no
end tell
tell current application
say “I am at point 33”
end tell
tell application “Adobe Acrobat Pro”
close document “TEST_VPack_TEST_LR.pdf” saving no
end tell
tell application “Finder”
set frontmost of process “Finder” to true
→ error number -1799 from process “Finder”
end tell
tell application “System Events”
set frontmost of process “Finder” to true
end tell
tell application “Finder”
display dialog " ✖︎ Open the NEW combined file you just made? " buttons {" ¢ YES ¢ ", " ¢ NO ¢ “} default button 2
→ {button returned:” ¢ NO ¢ "}
end tell
tell application “Adobe Acrobat Pro”
quit
→ error number 0
end tell
(1) OK, my guess about a possible error in the syntax was wrong.
(2) I am puzzled. The events log which you posted is reporting a complete flow of tasks and it’s was certainly not issued by my late version of the script in which I removed most of the tell me to say instructions.
And in my late version, I removed the instructions speaking to application Finder and process Finder which were perfectly useless and generated :
→ error number -1799 from process “Finder”
which is a non-fatal one with your code.
Was it really issued when you ran the application ?
If it was, I am interested to know how you get an application to issue an events log.
What you posted resemble to what I get when I run a script from the Script Editor.
But maybe I missed a feature somewhere.
(3) This said, the fact that I am puzzled is not important.
We know which is the failing instruction but, as I don’t own/use Adobe Acrobat Pro, I can’t explain why it is failing.
I may just hope that an other helper will be able to understand what is striking.
Yvan KOENIG (VALLAURIS, France) jeudi 19 février 2015 17:07:24
Hi Yvan -
Bonjour by the way, I guess you speak french (if I see from where you are.)
The issue, when I launch (and run automatically) the application (based on the Applescript) is that
at “point 71”, well the application simply “stops” and displays a window within the error msg. I wrote at the beginning (ie. “Can’t make document “test_XXX.pdf” of application “Adobe Acrobat Pro” into the expected type.”)
What’s really bother me is that the script runs perfectly if I launch it as a script within the Applescript editor.
I only get an error when I export the script as an small application.
But I can’t get an “events log” when the script is launched as an autonomous application.
True, my real language is French, the second is AppleScript and the 3rd is English.
(1) Look at the changes which I introduced in the late version of the script above.
I made a bit of useful cleaning.
(2) I repeat :
We know which is the failing instruction but, as I don’t own/use Adobe Acrobat Pro, I can’t explain why it is failing.
I may just hope that an other helper will be able to understand what is striking.
(3) to help helpers, it would be fine to tell us if the document reported in the error message :
“Can’t make document “test_XXX.pdf” of application “Adobe Acrobat Pro” into the expected type.”
is :
“TEST_VPack_TEST_HR.pdf” which is original_Document
or
“TEST_VPack_TEST_LR.pdf” which is Insert_Document
Good luck.
Yvan KOENIG (VALLAURIS, France) jeudi 19 février 2015 17:36:13