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


Click here to return to the 'Open Dashboard via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open Dashboard via AppleScript
Authored by: qwerty denzel on Jul 28, '06 12:05:33AM
The following has been taken from my script that I made in response to the original applescript speech hint mentioned in this hint. It simply parses the com.apple.symbolichotkeys.plist file in your user's preferences folder, and tries to construct a key command from there, complete with modifiers (command, option, etc.).
-- Open Dashboard
performActionForCode(|Dashboard|)

----- Action Codes -----
property |All Windows| : 32
property |All Windows Slow| : 34
property |Application Windows| : 33
property |Application Windows Slow| : 35
property |Desktop| : 36
property |Desktop Slow| : 37
property |Dashboard| : 62
property |Dashboard Slow| : 63

----- Action Commands -----
property commandList : {{commands:{"Show All Windows", "Exposé 1"}, code:|All Windows|}, ¬
	{commands:{"Show All Windows Slow", "Exposé 1 Slow"}, code:|All Windows Slow|}, ¬
	{commands:{"Show Application Windows", "Exposé 2"}, code:|Application Windows|}, ¬
	{commands:{"Show Application Windows Slow", "Exposé 2 Slow"}, code:|Application Windows Slow|}, ¬
	{commands:{"Show Desktop", "Exposé 3"}, code:|Desktop|}, ¬
	{commands:{"Show Desktop Slow", "Exposé 3 Slow"}, code:|Desktop Slow|}, ¬
	{commands:{"Show Dashboard", "Dashboard"}, code:|Dashboard|}, ¬
	{commands:{"Show Dashboard Slow", "Dashboard Slow"}, code:|Dashboard Slow|}}
property timePeriod : 30

on performActionForCode(actionCode)
	set keyProperties to getPropertiesForActionCode(|Dashboard|)
	
	if keyProperties is missing value then
		say "Key was not found for action!"
	else
		set keyCodeScript to {"tell application \"System Events\" to key code " & ¬
			keyCode of keyProperties & " using {"}
		tell keyModifiers of keyProperties
			if its commandDown then set keyCodeScript to keyCodeScript & "command down"
			if its controlDown then set keyCodeScript to keyCodeScript & "control down"
			if its optionDown then set keyCodeScript to keyCodeScript & "option down"
			if its shiftDown then set keyCodeScript to keyCodeScript & "shift down"
		end tell
		set {tids, text item delimiters} to {text item delimiters, ", "}
		tell keyCodeScript to set keyCodeScript to beginning & (rest as string) & "}"
		set text item delimiters to tids
		
		run script keyCodeScript
	end if
end performActionForCode

on getPropertiesForActionCode(actionCode)
	tell (do shell script "defaults read com.apple.symbolichotkeys AppleSymbolicHotKeys | sed '/" & ¬
		actionCode & "/!d; /enabled = 0/d; s/^.*parameters = (//; s/).*//; s/, /" & return & "/g;q'") to ¬
		if (count of it) is not 0 then return {keyCode:paragraph 2 as number, ¬
		keyModifiers:my getKeyModifiersForCode(paragraph 3 as number)} ¬
			
	
	return missing value
end getPropertiesForActionCode

on getKeyModifiersForCode(keyModifierCode)
	tell keyModifierCode div 131072 to ¬
		return {shiftDown:it mod 2 is 1, controlDown:it mod 4 div 2 is 1, ¬
		optionDown:it mod 8 div 4 is 1, commandDown:it div 8 is 1} ¬
			
end getKeyModifiersForCode


[ Reply to This | # ]
Open Dashboard via AppleScript
Authored by: qwerty denzel on Jul 28, '06 12:18:29AM

Note: since the script uses the key command to open Dashboard, it can also close it using the exact same method.

P.S. Sorry about the length and width of the script!



[ Reply to This | # ]
Open Dashboard via AppleScript
Authored by: qwerty denzel on Jul 29, '06 02:20:00AM

*Sigh*
Also, since this was just a hack-and-paste, I accidentally left in the script the property 'commandList'. It is not used or needed, so delete it. I would myself, but it's been set in stone (no editing available).



[ Reply to This | # ]
Open Dashboard via AppleScript
Authored by: inemo on Jul 28, '06 02:14:56PM

This is the kind of script that is needed, it doesn't matter what the user has changed it to :)

---
http://caius.name/

I'm just a mac baby :)



[ Reply to This | # ]