Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A better way to activate menu items from AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A better way to activate menu items from AppleScript
Authored by: PDXIII on Sep 26, '13 09:26:28AM

This is still a brilliant helper function, but It does not work when I try to put it in a loop. What’s the problem with that. Sorry, I am not good in applescript.

I would like to make the same action for a couple of selected files in Adobe Acrobat. It works well for a single file but not with a selection.

Greetz,
PDXIII

[code]
-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.

on menu_click(mList)
local appName, topMenu, r

-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"

-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)

-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
local f, r

-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse

-- main function below

tell application "Finder"
try
repeat with currentFile in items of (get selection)
set filepath to currentFile as text
tell application "Adobe Acrobat Pro"
open filepath

menu_click({"Acrobat", "Datei", "Speichern als...", "PDF mit erweiterten Reader-Funktionen", "Kommentieren und messen aktivieren..."})


end tell
end repeat
on error e
return e
end try
end tell

[/code]



[ Reply to This | # ]