Can Applescript handle this?

So I’m about to dive into learning Applescript, Its something I’ve been wanting to do for a while. But I have a specific thing I’m trying to accomplish, and I wanted to know that it’s possible through applescript before I put this time into it.

So heres my problem. I have a laptop and a monitor at work that runs off the laptop. I’m a very heavy spaces user. What I’m looking to do is have a set of spaces application assignments for home when I’m on a single monitor (So this application goes in space 1, this app goes in space 2, etc), and then I’d like to have a different set of application preferences for when I’m connected to a monitor, (since I have more than double the real estate, I can have 2 apps running in 1 space for example).

I’ve done a little bit of research, and I understand theres no direct way to detect when a screen is connected, and I’m more than happy to just run a script each time i connect or disconnect the monitor.

But ultimately I’m wondering if applescript is able to control and automate that list of spaces applications assignments, or will I be working towards an impossible goal by learning applescript right now?

Maybe, just MAYBE, you could change the settings in a plist file (if it’s in one) from the name of the network your on. You know, you would use network “HOME” at home and network “WORK” at work. AppleScript would pick up the name and write your settings to a file that Spaces would read.

Hello.

There shouldn’t be a problem at all. :slight_smile:
Especially If you have your screen configurations hardcoded, and scripts the scripts in the context of yourself, not trying to generalize it.
When You generalize this, you’ll open a can of worms. So you must for instance hardcode your screen resolution and things like that, script in the understanding of where the menubar is supposed to be, and the dock. If you do such thing, you might get a working solution quickly.

There are a lot of scripts both here and at macosxhints.com that you can use on your quest.

Best Regards

McUsr

hmm I’ve got two conflicting responses both from experienced members. I’m going through the beginner tutorials as we speak and have only really seen application control. I haven’t come across anything such as system prefs.

Can anyone else clear up if this is possible or not? :confused:

edit
As soon as I posted that I went and searched through the library and found the spaces application bindings. Looks like exactly what i’m looking for! Now I just have to learn how to use them :stuck_out_tongue:

I’ll keep the thread updated if I figure it out!

WOW, I’m starting to see the power of Applescript! This is awesome! Went through about half the beginner tutorials and figured it out. Wasn’t bad at all!

Here’s what I came up with:


--Pulls Current Spaces Settings
tell application "System Events"
	
	tell spaces preferences of expose preferences
		
		set app_layout to application bindings
		
	end tell
	
end tell

--Set Application Spaces Here
set app_layout's |com.apple.ichat| to 1
set app_layout's |com.apple.itunes| to 3
set app_layout's |com.google.chrome| to 1
set app_layout's |org.mozilla.firefox| to 1
set app_layout's |com.adobe.photoshop| to 3
set app_layout's |com.apple.iphoto| to 9
set app_layout's |com.adobe.indesign| to 3
set app_layout's |com.apple.ical| to 2
set app_layout's |org.videolan.vlc| to 4
set app_layout's |com.apple.mail| to 2
set app_layout's |com.adobe.illustrator| to 3
set app_layout's |com.echofon.echofon| to 1

--Activates New Settings for Spaces
tell application "System Events"
	
	tell spaces preferences of expose preferences
		
		set application bindings to app_layout
		
	end tell
	
end tell

and then I just created another script for a separate profile when I’m on a single monitor.

I understand I probably could have used “and’s” to set all of the app_layout properties, but I feel like this was cleaner, and easier to read if I need to change them.

Anyways, I think I’m hooked on this stuff, even after making a simple little script like that :smiley: . I’d like to explore resizing and moving windows with this in the future too.