Switch Control

Hi,

Has anyone succeeded in assigning a function key to an AppleScript with Switch Control. It’s in System Preferences > Accessibility if you don’t know. This is the first time I’ve used this. I can assign a button but can’t get the function key to work.

Thanks,
kel

Nevermind, I assigned the key and it worked.

Thanks anyway,
kel

Hello.

I mind! :smiley:

I use to make an Automator Service with a run applescript in it, where I first ass ign hfs path as alias, to a local variable,
then I run script the local variable.
That way the shortcut will be updated with the latest version, without me having to re compile the Automator service.

Or at least so I believe. I also have a kindo of centralized access to my short cut key, and can set their scope betweeen application and global when I create the service.

on run {input, parameters}
	local hfsScriptName
	set hfsScriptName to "harddisk:path:to:Elevate.scpt"
	run script (hfsScriptName as alias)
end run

It doesn’t seem to execute any slower than when I don’t scope the variables as local, making them to be saved, on the contrary…

Hi McUsr,

I was thinking about using a panel as a list of function keys with their functions. I never can remember which services are assigned to which function keys :slight_smile: . Still trying to figure out the best way to open a panel through AppleScript. This is how I enable Switch Control:

tell application "Switch Control"
	launch
end tell

Another thing is that the Space Input switch is obtrusive. I think I need to change from Space to some other key. This will waste a shortcut.

Note that with Switch Control, you can assign to certain apps just like an Automator service.

Still thinking about any advantages to Switch Control besides that it’s easier to assign shortcuts.

Have a good day,
kel

Hello.

I like to have all things concerning short cut keys in one place, that way I have the full overview, with concerns to services, and to overrides of application menus, and everything from the keyboard preferences pane.

Now, I could have been lazy, and had a special short cut key to reveal the keyboard preferences pane, but my fav. shortcut is an automator service, that reveal system preferences, I have assigned it cmd opt “,”.

Maybe there are some advantages to Switch Control.

Have a good night. :slight_smile:

Hello.

When you want to use the same short cut key in several apps, you can get away with it by using the code below, and add an if else clause at the end of it, so you run application specific scripts.

For a well defined environment. :smiley:

 on run {input, parameters}
	set appAlis to path to frontmost application

tell application id "com.apple.finder" -- 
	set nm to name of appAlis
end tell
tell (a reference to text item delimiters)
	set {tids, contents} to {contents, "."}
	set appName to text item 1 of nm
	set contents to tids
end tell
# If tests here, to invoke app specific scripts.
tell application appName
	display dialog appName
end tell
	
	return input
end run

Hello.

I have been thinking a little about this, and I can’t but agree that well … it is a litle bit cumbersome to assign short cut keys via the System Preferences pane. But on the contrary, then you have centralized repository, and the service menu under most apps Application menu will also reveal some of your short cuts, which is a great help in the beginning, before they are worked into muscle memory.

I have written a little script for revealing the shortcuts in the preference pane.

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.keyboard"
	reveal anchor 3 of pane id "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences" to tell window 1
	tell table 1 of scroll area 1 of splitter group 1 of tab group 1 
		set selected of row 6 to true
	end tell
end tell

There are a couple of missing steps here for creating the short cut, The “main” script, should call the script above, also show a dialog, which asks for the name of the service, and then copy an "Automator template with an Applescript action in it into ~/Library/Services with that name. The next step, is to switch to the editor, and get the hfs path of the front document, and create the “meat” of the Applescript action with that, put it onto the clipboard, post a notification and switch to Automator, and open the stored service.

(Here is a little piece that may be of use for the Automator part, once you have created the template and stored it somewhere.)

tell application "Automator"
	open ServiceTemplate
end tell
-- by passing a nagging dialogue.
tell application id "com.apple.systemevents" to tell application process "Autmator"
	keystroke tab
	keystroke space
end tell