PDA

View Full Version : GUI Scripting


djl
11-24-2005, 06:32 AM
Hi,
Does anyone know how to GUI script the Finder's contextual menu items?
ie, How do you go about control(right)-clicking an item and then selecting an option?
I've had a look and can't seem to get it working.
Thanks,

djl

hayne
11-24-2005, 06:51 AM
I don't know the answer, but all functionality that is available from the contextual menus should also be available elsewhere - from the main menubar, or buttons on the interface, etc.

What is it that you are trying to do?

djl
11-24-2005, 07:06 AM
Have a script app in the Finder toolbar that selects all files in the current folder and starts a slideshow. The select all I can do no problem, just the starting the slideshow is stumping me.

djl
11-24-2005, 07:07 AM
btw, the slideshow option doesn't appear in any menus, if it did then obviously I would have scripted accordingly

hayne
11-24-2005, 07:15 AM
btw, the slideshow option doesn't appear in any menus

True - and that seems bad (contrary to the UI guidelines).
But it is in the "action" menu (the control that looks like a gear) which is in the Finder toolbar by default.

djl
11-24-2005, 08:48 AM
Success!!! :)

OK, thanks to Hayne here's the script:-

-- Firstly, this script assumes a couple of things, namely;
-- 1. The first 3 elements of your Finder toolbar are
-- the default (ie, Back, Path and Action)
-- 2. You've navigated to a folder full of images
--
-- What it does;
--
-- Using GUI scripting it performs the equivalent of a
-- 'Select All' (Command+A) followed by either:-
--
-- a control(right)-click of the highlighted files to show
-- a contextual menu where 'Slideshow' is then selected
--
-- or (what the rest of the GUI scripting actually does)
-- clicks the Action (cog) menu and selects 'Slideshow'
--
-- The slide show will then start and display all the selected files
--
-- You can save this as a script application, put a nice icon on it
-- and then drag it to either the Toolbar or Sidebar for quick,
-- convenient access from any Finder window
-- Feel free to modify the source to further suit your needs, enjoy!
-- djl, Nov 2005
-- Thanks to Hayne at macosxhints.com
--
tell application "Finder"
activate
set winName to get name of window 1
end tell
tell application "System Events"
tell process "Finder"
keystroke "a" using {command down}
click menu button 1 of group 3 of tool bar 1 of window winName
click menu item 16 of UI element 2
end tell
end tell

mark hunte
11-24-2005, 10:31 AM
Hey thats great.
I changed it a small bit.

The main change is the number "click menu item 16 of UI element 2"
to
"click menu item "Slideshow" of UI element 2"

Mine was 15 and finding which number worked you may select the wrong menu.
(like move to trash or make archive)

So this makes no mistakes.

also for those of you who may not know what ""1. The first 3 elements of your Finder toolbar are
-- the default (ie, Back, Path and Action)"" are

it means you toolbar looks like this


http://uk.geocities.com/markosx@btinternet.com/Picture_5.png

You can move them around using the "Customize toolbar" menu.

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

tell application "Finder"
activate
set winName to get name of window 1
set these_files to every file of window 1 whose
file type is in the type_list or name extension is in the extension_list
set winName to get name of window 1
select these_files
end tell
tell application "System Events"
tell process "Finder"
click menu button 1 of group 3 of tool bar 1 of window winName
click menu item "Slideshow" of UI element 2
end tell
end tell

djl
11-24-2005, 02:34 PM
Nice one Mark :)