Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,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 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[4,693 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 whomever posted them. This site is not responsible for what they say.
10.5: Find current Space number via AppleScript
Authored by: CajunLuke on Tue, Mar 4 2008 at 6:56PM PST
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 Wed, Mar 5 2008 at 7:04AM PST
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 Wed, Mar 5 2008 at 12:07PM PST
"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 Thu, May 8 2008 at 2:54PM PDT
A bit different, but is it possible to trigger an AppleScript when the current space is changed?

[ Reply to This | # ]