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

Create your own speakable items via AppleScript System
The recently-posted Control Exposť via AppleScript and voice hint reminded me of a hint I posted in the Mac OS X Hints Forums. You do not need an AppleScript application running, just get Speakable Items to do what you want with your own words. You can also use small scripts placed in the Speakable Items folder -- ~/Library/Speech/Speakable Items.

Here's an example: I want to say the word Widgets, and have the Dashboard show (or hide if it's showing). To do this, I make an AppleScript with this code:
on run
  try
    tell application "System Events" to key code 111 --F12
  end try
end run
Save the script in the Speakable Items folder with the name Widgets, and with the extension hidden. Now when you have Speakable Items enabled (I have mine set to listen continuously) and say the word Widgets, the Dashboard will show or hide. You enable/disable Speakable Items in the Speech System Preferences panel.
    •    
  • Currently 3.20 / 5
  You rated: 4 / 5 (5 votes cast)
 
[30,261 views]  

Create your own speakable items via AppleScript | 12 comments | Create New Account
Click here to return to the 'Create your own speakable items via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create your own speakable items via AppleScript
Authored by: inemo on Jul 27, '06 10:25:06AM

Or you could just put an alias to the Dashboard.app in the speakable folder and name it "widgets". Then you just speak widget and it opens the dashboard. Doesn't even need to wait the few milliseconds it takes the script to fire either ;)

---
http://caius.name/

I'm just a mac baby :)



[ Reply to This | # ]
Create your own speakable items via AppleScript
Authored by: inemo on Jul 27, '06 11:29:40AM

Also rather than pressing F12 (which assumes that people have left the dashboard assigned to F12, rather dangerous in my opinion) you can activate the dashboard with this one line script:

do shell script "open -a /Applications/Dashboard.app"

---
http://caius.name/

I'm just a mac baby :)

[ Reply to This | # ]

Create your own speakable items via AppleScript
Authored by: splatkus on Jul 27, '06 11:50:53AM

OK, so how would you then exit out of Dashboard in a script without using the F12 key command?



[ Reply to This | # ]
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 | # ]
Create your own speakable items via AppleScript
Authored by: mark hunte on Jul 29, '06 01:00:58AM

Thanks For the comments, But this hint is about Speakable items, the dashboard was just an example.

inemo's idea of putting aliases in the Speakable items folder is interesting and I will try that but not for dashboard, using iNemos way does not allow to hide it. But for many other apps it may be handy. But for many actions within apps the scripts are better.

---
mh



[ Reply to This | # ]
How to create responses
Authored by: lewisi on Jul 31, '06 09:12:31AM

Does anyone know how to use scripts to have the mac respond. As in i'll say hello and it has a pre created responce such as hello, hey, or whats up?



[ Reply to This | # ]
How to create responses
Authored by: mark hunte on Jul 31, '06 11:10:11AM
Just follow my hint.

But to recap using what you want as an example.

Copy this code in to a New 'Script Editor' Document
Click the compile button (image of a hammer).
Save as a Script , Hide Extension TICKED. and Its Name Hello
Put it into ~/Library/Speech/Speakable Items

on run
	try
		tell application "System Events"
			set full_name to full name of current user as string
			set first_name to first word of full_name as string
		end tell
		say "Hello " & first_name & ", hey,   whats up?"
	end try
end run

Now when you say Hello, it will reply "Hello 'Your first name' , hey, Whats up"

---
mh

[ Reply to This | # ]

How to create responses
Authored by: lewisi on Jul 31, '06 05:32:08PM

is there any way to make the responses random?



[ Reply to This | # ]
How to create responses
Authored by: mark hunte on Aug 16, '06 10:09:09AM
Try This.

property random : {}
property Last_random : {}
on run
	try
		tell application "System Events"
			set full_name to full name of current user as string
			set first_name to first word of full_name as string
		end tell
		set greet_1 to "Hello " & first_name & ", hey,   whats up?"
		set greet_2 to first_name & ", Hello " & ", hey,   whats up?"
		set greet_3 to "Hey,   whats up?" & first_name
		set greet_4 to "Hello ,, Me Olda Muckare"
		set greeting_list to {greet_1, greet_2, greet_3, greet_4}
		repeat until random is not Last_random
			set random to random number from 1 to count of items in greeting_list
		end repeat
		set Last_random to random
		say item random of greeting_list
	end try
end run

---
mh

[ Reply to This | # ]