Switch Displays w/ Applescript

Discussion in 'macOS' started by photon43, Jun 13, 2010.

  1. photon43 macrumors newbie

    Nov 3, 2009
    This is one of those things that I think should be really easy to do but for some reason I can't find any useful info on it.

    I have one of the new iMac 21" models and a 42" HDTV mounted above it - great for movies and a general media center. Now, when I want to watch a movie I have to do several things to prep for this:

    1) Open system prefs and switch the main display to the top 42" screen.
    2) Open the desktop and screen saver pane and set the desktop BG to solid black for the lower screen (b/c there is no way to shut it off and having it any other color is distracting during a movie)

    Now, none of this is particularly annoying really, But… It does take like 7 or more clicks to get it done.

    I would like to automate the whole process of course - b/c I should be able to, there is just no reason why not. I want to run a script that switches the desktop from bottom to top monitor, changes the desktop BG from gray to black at the bottom monitor (the iMac) and then have another script that does this all in reverse (more on this idea below) for when I need to get back to work. It really does not seem like such a tall order but I can find no answers anywhere.

    The following script is the best I could find (I did not write this - just modified the paths a bit) but all it does is change the BG of the desktop:

    set buttonList to {"work", "movies"}
    set colorList to {"Solid Gray Medium", "Solid Black"}
    display dialog "Which environment?" buttons buttonList default button 1
    set selectedButton to the button returned of the result

    repeat with index from 1 to 3
    if item index of buttonList = selectedButton then exit repeat
    end repeat

    set selectedColor to item index of colorList

    tell application "Finder"
    set desktop picture to {"BobaFett4:Library:Desktop Pictures:Solid Colors:" & selectedColor & ".png"} as alias
    end tell

    I need it to go a bit further but this is perfect because it eliminates the need for the 'reverse' script I was talking about before because of the buttons it gives me. I could just switch between the two sates (work and movies) at will if I could get some code that would take care of the main display switch along with the BG color switch. But I cant figure out how to take this to the next level. Please help if you can. Thanks!
  2. kasakka macrumors 68000

    Oct 25, 2008
    Why don't you just use a player that has a "blank other screen" option? Movist and VLC do this. You can set the display used for movies by dragging the player on the display or selecting it from options.
  3. photon43 thread starter macrumors newbie

    Nov 3, 2009
    Well, thanks for the suggestion but its not really much of an answer, is it? I play movies using the DivX player from within my browser. I can pop it out and use it up top if I want to but I want to do this actionscript method I mentioned.

    I am not looking for the simplest workaround type answer I can find, I am looking for the best real answer I can find. This has a double function: 1) I will get the functionality I am looking for on my system, 2) I will see how the applescript is working and learn a thing or five about it. #2 has as much value as #1 to me.

    Again, If you can help with the applescript request, please do. Thanks all!
  4. kasakka macrumors 68000

    Oct 25, 2008
    You should've mentioned that you use a browser based player...

    Anyway, the easiest solution would be to simply move the browser window on the other display using AppleScript, then hide the Dock and set the background to black. For moving the browser use

    tell "System Events"
    tell process "Firefox"
    set position of front window to {x,y}
    end tell
    end tell

    Instead of buttons to toggle, you could just have some if logic to determine which state is active so you don't have to click anything but one icon to do what you want.

    You can use Platypus to turn your Applescript into an application that you can just doubleclick on your desktop for example.

Share This Page