Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Script contextual menu?

Script contextual menu?
Thread Tools
tngland
Fresh-Faced Recruit
Join Date: Oct 1999
Location: Decatur
Status: Offline
Reply With Quote
May 4, 2000, 05:13 AM
 
Has anybody found a way to script a contextual menu command?
Specifically, I want to script TitleFree, a great little plugin that makes the names (and white label) of your desktop icons go away-- for a cleaner desktop. However, it can only be triggered by a contextual menu (and a submenu at that) in the Finder. I have tried recording the manuever with both Applescript and OneClick with no success.

------------------
     
Paul Crawford
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
May 7, 2000, 06:23 AM
 
Hi,

If you haven't already done so, you could try searching in the MACSCRPT mailing list (available via Dartmouth's MACSCRPT Hub), or in any of the other resources listed in the New to AppleScript topic in this Forum. I myself don't believe that it's possible to script contextual menu item selections through AppleScript, at least not in current versions of the Mac OS. Such menus are not only modal but also dynamic (built "on the fly"), and controlling them would probably require patching the system's contextual menu manager (CMM) routines.

On the other hand, if I remember rightly, older versions of the Title Free extension allowed you to use keystroke-combinations to activate its features; this latter task is easily handled by AppleScript with the help of third-party scripting additions (OSAXen). If the latest version of Title Free no longer accepts key-stroke-combinations, and the extension isn't directly scriptable, you may have better luck with a third-party control panel or extension (perhaps QuicKeys?) that can select menu items from modal dynamic menus (similarly to how 'Okey Dokey Pro' can auto-select buttons in modal dialogs).

Just to clarify a little... In AppleScript, it's fairly easy to *display* a contextual menu by simulating a control-click, via a third-party scripting addition (OSAX) such as S�ndi's Additions (MouseClick At {x, y} with Control) or Akua Sweets (input state {pointer location:{x, y}, button down:true, control key bit:true}). However, it's not so easy to then *select* a menu item from the contextual menu. The stumbling block is that the menu display is usually modal, and the host app (such as the Finder) doesn't get a chance to respond to further script commands that try to select a menu item.

For instance, here's a short script that uses the S�ndi's Additions OSAX. The script first displays the contextual menu for my startup disk in the Finder (this works well), and then tries to select the second menu item (usually 'Open') from the contextual menu (this fails miserably):-
Code:
tell application "Finder" -- Bring the app frontmost, to accept clicks activate -- Control-click on the startup-disk icon at the upper-right corner of my desktop, to display a contextual menu set theItemPos to (position of startup disk) -- Get the upper-left coordinates of the icon bounds set theItemPos to {((item 1 of theItemPos) + 15), ((item 2 of theItemPos) + 15)} -- Adjust to icon's center MouseClick At theItemPos with Control -- Simulate a control-click on the icon -- Try to select the second menu item (usually, 'Open'), from the contextual menu displayed to the icon's left -- //NOTE: THIS DOES NOT WORK! (The contextual menu display is modal) set theCMMMenuItemPos to {((item 1 of theItemPos) - 30), ((item 2 of theItemPos) + 5)} MouseClick At theCMMMenuItemPos end tell
Actually, I'd be very interested to hear of any AppleScript workarounds for this issue. [Some non-AppleScript solutions that worked in the past were provided by control panels or extensions such as Respond! or Menu Tasker, which allowed "multi-tasking" for modal menus, but these no longer work with Mac OS 8.5 or later.]

Regards,

--Paul

[This message has been edited by Paul Crawford (edited 05-07-2000).]
     
tngland  (op)
Fresh-Faced Recruit
Join Date: Oct 1999
Location: Decatur
Status: Offline
Reply With Quote
May 8, 2000, 04:52 AM
 
Thanks for your info. Although I have these OSAX, I will not familar with the mouse-down- with-control. With it I was able to generate the contextual menu onscreen. Still, I couldn't select the option I want since it is actually in a submenu. I'm trying to use OneClick (handy since you can call an Applescript from OneClick and vice-versa--so you can combine what might be possible in one or the other).
And, since the menu is dynamic, I can't reliably script cursor co-ordinates.
You are quite right that TitleFree used to have key commands. I emailed the author and he just wished me luck.
But since I began this quest I have realized that my original goal of scripting my desktop icon positions as part of scripts which change my desktop picture is easily accomplished by simply recording those moves with TitleFree off. Then I leave TitleFree on and invoke those moves via those scripts.
So I'm able to do what I want, but I remain curious about scripting CMM's. If I find anything, I'll post it here.


------------------
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:25 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,