You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Spaces Script Control Problem

Hey, everyone,


During work hours, I've enabled Spaces and assigned various apps to their own Spaces. However, I game off-hours, and I've found that the keyboard shortcuts I have set up for Exposé, Dashboard and Spaces interfere with my in-game controls. (I need the function keys free.)


Being kind've a nerd (*gasp*) I thought it'd be neat to set up an Automator action such that I could hit a button, and Exposé, Dashboard and Spaces would be disabled, saving me having to go to the System Preferences each time. And I've got one that mostly works.


I set up Automator to run a shell script, which contains the following:


defaults write com.apple.dock mcx-expose-disabled -bool true

defaults write com.apple.dashboard mcx-disabled -boolean YES

/usr/libexec/PlistBuddy -c 'Set :workspaces-app-bindings:com.apple.safari 1' /Users/MyUserName/Library/Preferences/com.apple.dock.plist

/usr/libexec/PlistBuddy -c 'Set :workspaces-app-bindings:com.apple.serveradmin 1' /Users/MyUserName/Library/Preferences/com.apple.dock.plist

/usr/libexec/PlistBuddy -c 'Set :workspaces-app-bindings:com.apple.mail 1' /Users/MyUserName/Library/Preferences/com.apple.dock.plist

/usr/libexec/PlistBuddy -c 'Set :workspaces-app-bindings:com.apple.itunes 1' /Users/MyUserName/Library/Preferences/com.apple.dock.plist

defaults write com.apple.dock workspaces -bool NO

killall Dock

The first two lines disable Exposé and Dashboard. The last two lines disable Spaces and restart the Dock to make the changes take place.


Here's the problem: occasionally, I want to be in "game-mode", but I'd still like to quickly check Mail, or look something up in Safari. However, when I try to launch, say, Safari, it opens the window in its assigned Space, despite the fact that Spaces is disabled - and of course, with Spaces disabled, I can't get to the window. Attempting to open a new window through various means just opens new windows off-screen.


I can go to System Preferences and toggle the "Enable Spaces" checkbox on and off again, and then the app windows show up properly, but this sort've defeats the purpose of scripting it in the first place.


The middle four lines of the code are an attempt to change the Space assignment for the apps in which I'm interested prior to disable Spaces. I know it works, because I've checked com.apple.dock.plist, and it does in fact properly change their Space assignment - but it does not have any effect.


Since I can toggle the Spaces checkbox and achieve what I desire, I can't help thinking that all I'm lacking is a way to make Spaces understand that the preferences have changed, or to reset it, or clear a cache, or whatever happens when things are changed via the preference pane.


I've been all over Google, but I can't seem to find any help. I'm hoping somebody here'll be able to help me out?

MacBook Pro, Mac OS X (10.6.7)

Posted on May 8, 2011 9:13 PM

Reply
Question marked as Top-ranking reply

Posted on May 9, 2011 3:05 PM

Hi!


Changes in Spaces Preferences will send a notification to Spaces.app. -- A Plist can not send any notifications.

So you need to dis/enable Spaces from Spaces Preferences. There is a way to do this with the help of AppleScript since Spaces Preferences is scriptable:


tell application "System Events"

tell expose preferences

tell spaces preferences

set spaces enabled to false


-- delay 0.2

set spaces enabled to true


-- delay 0.2

set spaces enabled to false

end tell

end tell

end tell


maybe you need to remove the - - and activate a short delay

(Use the "Run Apple-Script" action)

2 replies
Question marked as Top-ranking reply

May 9, 2011 3:05 PM in response to Gryphon

Hi!


Changes in Spaces Preferences will send a notification to Spaces.app. -- A Plist can not send any notifications.

So you need to dis/enable Spaces from Spaces Preferences. There is a way to do this with the help of AppleScript since Spaces Preferences is scriptable:


tell application "System Events"

tell expose preferences

tell spaces preferences

set spaces enabled to false


-- delay 0.2

set spaces enabled to true


-- delay 0.2

set spaces enabled to false

end tell

end tell

end tell


maybe you need to remove the - - and activate a short delay

(Use the "Run Apple-Script" action)

Spaces Script Control Problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.