Does anyone know a creative way to set the active Adobe Acrobat document based on its name? For example, suppose I have three documents currently open: “document1.pdf,” “document2.pdf,” and “document3.pdf.” Currently, “document3.pdf” is the frontmost. What I am seeking, is a method to set “document1.pdf” to the frontmost document.
The script below is obviously not working, but it may provide more clarity on what I am seeking:
tell application id "com.adobe.Acrobat.Pro"
activate
set targetDocName to "MyTestFile.pdf"
-- Flag to check if document is found
set docFound to false
-- Iterate through open documents to find the one with the matching name
repeat with i from 1 to count of documents
if (name of document i) is targetDocName then
display dialog "I found the document as one of the documents currently open but possibly not active"
-- Activate the document
set docFound to true
set theDoc to document i
set theDoc to frontmost
exit repeat
end if
end repeat
end tell
I don’t have acrobat so it may have slightly different terminology but in general, you set the ‘index’ to 1.
Here is an example with textedit:
tell application "TextEdit"
documents
--> {document "removal-list" of application "TextEdit", document "find by newer-older range.rtf" of application "TextEdit"}
windows
--> {window id 16347 of application "TextEdit", window id 16346 of application "TextEdit"}
name of window id 16347 -- "removal-list"
name of window id 16346 -- "find by newer-older range.rtf"
set index of window 2 to 1
name of window 1
--> "find by newer-older range.rtf"
end tell
Note: In general, you’re actually dealing with windows here and not documents. Of course, you should confirm the below with Acrobat.
tell application "TextEdit" to index of documents
--> error "TextEdit got an error: Can’t get index of every document." number -1728 from index of every document
tell application "TextEdit" to index of windows
--> {1, 2}
However, I have no opinion on whether this would constitute a creative solution.
Thank you Mockman, but it appears that index is not accessible in Adobe Acrobat.
I figured out a solution. In my case, the file I wish to re-open would have already been saved. Therefore, I can compare all open documents and then reopen the file matches the name I am looking for, which will make it fronmost:
set docFound to false
tell application id "com.adobe.Acrobat.Pro"
activate
set targetDocName to "MyTestFile.pdf"
set docFound to false
-- Iterate through open documents to find the one with the matching name
set myCount to count of documents
repeat with i from 1 to myCount
--if (name of document i) is targetDocName then
set myName to name of document i
if myName is targetDocName then
set filePath to file alias of document i
set pdfFilePath to POSIX path of filePath
open pdfFilePath
set docFound to true
end if
end repeat
end tell
Hello Jeffkr,
Nice to meet you. I’m not very good at English, so I might misunderstand your intention.
Using JavaScript, tab operations in Acrobat are simple. I hope this helps.
Best regards.
set strFileName to ("MyTestFile.pdf") as text
tell application "Adobe Acrobat"
set numCntDoc to (count of every document) as integer
repeat with itemIntNo from 1 to (numCntDoc) by 1
tell document itemIntNo
set strDocName to name as text
end tell
if strDocName is strFileName then
set strTabNo to (itemIntNo - 1) as text
set strTabName to ("SwitchToTab" & strTabNo) as text
do script "app.execMenuItem(\"" & strTabName & "\")"
exit repeat
end if
end repeat
end tell
Hello IceFole,
You understood my intention perfectly! What you provided me with is exactly what I was looking for. This is absolutely fantastic, and I greatly appreciate the time you spent to share this with me.
set strFileName to "MyTestFile.pdf"
try
tell application "Adobe Acrobat" to bring to front (first document whose name is strFileName)
on error
-- no such document
end try