Applescript - Detect if Dock Contextual Menu Item is Checked?

Joined
Mar 26, 2009
Messages
2
Reaction score
0
Points
1
I've made an applescript stay open application that checks if Transmission is open, and Safari is frontmost, it selects speed limit from Transmission's dock icon.
It's SO **** useful, as my internet is fast and ready when I'm browsing, then if I'm not using it Transmission is free to take up the full bandwidth.

However, I can't seem to find any way to detect whether menu item "Speed Limit" is checked or not. It shows a little tick next to it when it's activated (I've attached a picture), so there MUST be a way to detect that (I hope).
Currently I'm using the property "transmissionLimited" to store whether or not my application has checked it automatically... but sometimes if I want to limit for other purposes it will then UN-LIMIT it when I open up Safari. Nightmare :Oops:

I've tried using "get ui elements" and "get properties" to no avail. Has anyone got any other ideas?

Also I don't really use forums much. Is there a better forum to ask this question on? Macscripter.net?

Thanks!



Here's what I'm using so far...



on checkTransmission()
try
if (isFrontmost("Safari")) and (isRunning("Transmission")) and (transmissionLimited is false) then
tell application "System Events" to tell process "Dock"
tell UI element "Transmission" of list 1
perform action "AXShowMenu"
click menu item "Speed Limit" of menu 1
end tell
end tell
set transmissionLimited to true
else if (isFrontmost("Safari") is false) and (isRunning("Transmission")) and (transmissionLimited) then
tell application "System Events" to tell process "Dock"
tell UI element "Transmission" of list 1
perform action "AXShowMenu"
click menu item "Speed Limit" of menu 1
end tell
end tell
set transmissionLimited to false
end if
on error
Growl("Auto Speed Limit Failed")
end try
end checkTransmission

transmissiondock.png
 
Joined
Mar 9, 2004
Messages
9,065
Reaction score
331
Points
83
Location
Munich
Your Mac's Specs
Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
Does Transmission have it's own Applescript dictionary? If it does you might try accessing the speed commands that way instead of going the ui scripting route.

If it doesn't you could also try running the command-line based version of transmission and then using a shell script command to throttle it.
 
Joined
Dec 26, 2010
Messages
1
Reaction score
0
Points
1
Thank you very much, your script has help me a lot :)

And I'm gonna help you!!

What you need if a menu is "checked" is the attribute AXMenuItemMarkChar, something like:

set isChecked to ((value of attribute "AXMenuItemMarkChar" of -themenuitem-) ≠ "")

that because AXMenuItemMarkChar is the tick char, if there isn't the check it is just nothing :)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top