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

10.5: Find current Space number via AppleScript System 10.5
One drag about Apple's Spaces implementation in Leopard is that there is no way to access Spaces via AppleScript. While you can use AppleScript to select indvidual spaces by simulating keystrokes, it'd be nice to have some way to find what the current space is via AppleScript.

Well, using PreFab Software's excellent UIBrowser, I was able to figure out how to accomplish that precise task with AppleScript.

(I believe you'll need to check Enable Access for Asssistive Devices in the Universal Access pane of System Preferences, if you haven't already, for this to work. You'll also need the Spaces menubar extra to be visible, which you can enable in the Spaces pane of System Preferences.)

The script will return the variable theCurrentSpace with the number of the currently displayed space. You can use that information in any way your scripting or automation imagination desires. Here is the AppleScript; copy and paste into Script Editor: [robg adds: I haven't tested this one.]
    •    
  • Currently 3.00 / 5
  You rated: 3 / 5 (6 votes cast)
 
[10,126 views]  

10.5: Find current Space number via AppleScript | 4 comments | Create New Account
Click here to return to the '10.5: Find current Space number via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Find current Space number via AppleScript
Authored by: CajunLuke on Mar 04, '08 06:56:55PM

If you go out to the "All Spaces" (F8) screen, the result is 65538.



[ Reply to This | # ]
10.5: Find current Space number via AppleScript
Authored by: wgscott on Mar 05, '08 07:04:50AM

This works (returns the number of the space I am in), but there really ought to be a better way.

Is there an applescript way to change to a specified space, or to get the application assigned in a space?




[ Reply to This | # ]
10.5: Find current Space number via AppleScript
Authored by: chucky23 on Mar 05, '08 12:07:57PM
"This works (returns the number of the space I am in), but there really ought to be a better way."

Agreed. Apple should have genuine AppleScript hooks into Spaces, but they don't as of yet.

I was amazed I was able to get this working just by using GUI scripting.

-----

"Is there an applescript way to change to a specified space"

Yup. Just simulate the keystroke with AppleScript.

For example, I have my prefs set up to switch to a space by hitting a number with control. So the following AppleScript will switch me to Space "1":

tell application "System Events"
keystroke "1" using control down
end tell

-----

"or to get the application assigned in a space?"

Check out this hint:

http://www.macosxhints.com/article.php?story=20071217092214986


[ Reply to This | # ]
10.5: Find current Space number via AppleScript
Authored by: CapnPolo on May 08, '08 02:54:31PM

A bit different, but is it possible to trigger an AppleScript when the current space is changed?



[ Reply to This | # ]