tags:

views:

387

answers:

3

Hi,

I wonder if it is possible in bash for OSX to create a script for which we give as input the application name and a number N, so this app gets opened in the Space's space number N.

I would like with this to create a meta-script, so when the computer boots and after login, on each space I get different apps, and important, I can change this in the script file, and not through mac os x Space's preferences

Thanks

A: 

defaults write com.apple.dock workspaces-app-bindings -dict-add com.apple.safari 4

That does from the command line the same thing as changing the spaces preferences to put safari in space number 4. 65544 would put it on all spaces.

As you can see, it's the dock that does the space binding.

Andrew McGregor
hi, are you sure? I type that on terminal, I ahve 6 spaces oepened, and safari does not show up
Werner
You may need to `killall Dock` to get your dock to reload its defaults.
Andrew McGregor
+1  A: 
#!/bin/sh
APPNAME=$1
SPACE=$2
APPID=$(osascript - <<EOF1 | tr '[:upper:]' '[:lower:]'
tell application "Finder"
    get id of application file "$APPNAME" of folder "Applications" of startup disk
end tell
EOF1
)
osascript - <<EOF2
tell application "System Events"
    set x to application bindings of spaces preferences of expose preferences
    set x to {|$APPID|:$SPACE} & x
    set application bindings of spaces preferences of expose preferences to x
end tell
EOF2
Ned Deily
P.S. It would have been better to edit and extend your original question rather than to open a second, almost identical question. And you would have received an answer sooner.
Ned Deily
Also, the script as presented only works for applications found in /Applications. Extending it to work for applications in other folders is left as an exercise to the reader.
Ned Deily
hi, yes you are right, sorry for the lack of good explanation. I will do like that the next time.
Werner
but i realizae that this is not what i am looking for.sorry i did not explain it well.with you script, an app gets assigned to some Space.then everytime I open it, it will go to that space, so i can not have two instances of the app in differente spaces.
Werner
I just need to know how to tell (in bash/applescript or whatever) to an instance of an application, to "move" to Space number N. I will open a new quesiton. thanks
Werner
A: 

This function has been implemented in the last version of OSX directly in System Preferences -> Exposé & Spaces -> Spaces -> Application Assignments

Frederic Rouge