Ok this is my problem. I recently broke out my old keyspan DMR and programed the remote into my sony uni remote to control itunes from the comfort of my lazy couch. my problem is when i want to switch apps, the keystroke is command-tab. but with the DMR its too fast and doesnt switch correctly. the DMR Mapper allows you to link an applescript to the buttons. ive been trying to figure out how to do it myself but this is really my first time using applescript. i need it to be somthing like: hold command pause 1 sec then press tab. thats all and it sounds really easy to do but im stuck. please help! thanks!
You’ll need to download and install the GUI Scripting beta (aka System Events 1.2). Don’t forget to make sure that “Enable access for assistive devices” is turned on in the Universal Access Preference pane. Then you can run the following script (save it as an application to allow other applications – like DMR – to launch it):
Jon
On second thought, that might not work as expected. When you launch the AS app above, it will become active and then it will tab to the next open app (which will probably be the app you were in before you called the AS app). You might be caught in a continuous loop. Hmm. Let me think about this some more…
Jon
ok well this is the problem, when you push command and tab you switch back and forth between the app u were youing and the app you just used, but if you hold command and push tab it switches to each open app. thats the outcome i want. so maybe somthing like hold command pause push tab but then have the push tab command in a loop and not the whole command+tab in a loop. sorry its not more specific terms but im learning
You can’t hold down the Command key and then hit other keys without releasing the Command key using AppleScript alone (anyone care to prove me wrong?) but you could do something like:
Saving this as an app and launching it from DMR is feasible I think. Does the DMR allow you to move up and down (simulate the up or down arrow keys) and then send an enter command? If so, this solution will work.
Jon
Leaving aside the question for the moment of why you’d want to use a Sony remote to switch applications when the frontmost application is irrelevant if you’re not sitting in front of the machine (in which case the mouse seems more appropriate), you might want to think of this the other way around.
It’s easy using AppleScript to activate specific applications:
tell application "AppName" to activate
and it’s also easy to hide the frontmost application:
tell application "System Events"
set frontapp to first application process whose frontmost is true
set visible of frontapp to false
end tell
Any combination of these two should get you what you want without having to resort to GUI Scripting and keystrokes.
I don’t have a Keyspan remote but the way I understand it, it allows you to remotely control the front application and is useful for applications like DVD player, iTunes, PowerPoint, Keynote, etc. when you are not in front of your machine but still need to control it (pause, play, mute, etc.). If you want to control more than one application, you’ll need a way to cycle through the open applications without hardcoding their names (although I guess you could). The solution I posted above allows you to do this although it isn’t perfect because the app list includes invisible processes that you’ll never want to activate.
While this should work in theory, if you save this script as an app, when you run it, it in fact becomes the front app and just hides itself. If you run it from Script Editor, then SE will always be front and you get the same result. Saving as a complied script and running from the Script Menu runs into a bug in Script Menu (also see this link) whereby it calls System Events and makes it the front app.
Jon
yeah thats basically all i want to do, switch from itunes to aim ( though i wont be able to enter text i can read it) to mail to system prefs. that first script works but yeah, its got 20 other programs running but arent any of the foremost apps i need.
If there’s a limited number of apps you want to activate, can’t you either assign different keys to each app, or use a property within the script and loop through them:
property theApps: {"Mail", "AIM', "iTunes"}
property currentApp: 1
on run
set currentApp to ((currentApp + 1) mod count of theApps)
set nextAppName to item currentApp of theApps as string
tell application nextAppName to activate
end run
Each time this runs, it selects the next item in the list and activates that application.
Oooh, so close. Very elegant but your mod function will return 0 when the counter = the count of apps and will throw and error trying to get item 0 to the_apps. This script will work. Add any apps you want to the list, save as an application and I think the thread is done.
Jon
Darn!