Hey newbie scripter here. We have a lot of teachers come in and ask our tech team how to mirror the display . So I wrote a small script that will mirror the display for you through Self Service. This will only work if there is an external display connected. It downloads a command line tool created by Fabian Canas and runs it.
( I was trying really hard to make a script myself to mirror the display but finding this command line tool made things way easier.)
#!/bin/bash ## Checking if file exists if [ -e /Library/Application Support/JAMF/tmp/mirror ] then ## running the executable /Library/Application Support/JAMF/tmp/mirror else ## if file doesn't exist cd /Library/Application Support/JAMF/tmp/ ## it will go ahead and download the file to the tmp directory curl -L "https://github.com/fcanas/mirror-displays/releases/download/1.0/MirrorTool.zip" > MirrorTool.zip sleep 2 unzip MirrorTool.zip sleep 0.5 ## it will then run the downloaded executable /Library/Application Support/JAMF/tmp/mirror fi exit 0
Definitely looking for any suggestions on how to change this up.
We wanted to store the file under the tmp folder, that can be changed to your taste.
Credit goes to Fabian Canas for making the Mirror Display Application and Command line Tool:
If you want to keep such command line utilities for future use, package them with Composer and install/store them in /usr/local/bin . I have several such binaries that I package together and push to all computers when the machines are initially deployed, then invoke them in policies as needed. This would also save bandwidth and protect against the github download being removed, which is nigh inevitable.
One other thing. I see a lot of people do this in scripts, but it's not necessary to
cd into a location, and then do a curl for a file. You can direct curl to download a file direct to a location without first cd'ing into the directory. For example
curl -L "https://github.com/fcanas/mirror-displays/releases/download/1.0/MirrorTool.zip" > "/Library/Application Support/JAMF/tmp/MirrorTool.zip" sleep 2 unzip "/Library/Application Support/JAMF/tmp/MirrorTool.zip" -d "/Library/Application Support/JAMF/tmp/" sleep 0.5
It's a minor thing, but just wanted to point it out as it avoids an unnecessary step in the overall sequence. It also means you can download a zip to one location and extract it to some other location, using the
-d flag as shown above. Example:
curl -L "https://github.com/fcanas/mirror-displays/releases/download/1.0/MirrorTool.zip" > /private/tmp/MirrorTool.zip unzip /private/tmp/MirrorTool.zip -d "/Library/Application Support/JAMF/bin/"
I really like the use of Self-Service. This is a great way to get attention there!
That said, part of me wonders if that's the best way to help them. Mirroring displays is a routine, near-daily task for some. It's also very simple. Not only is it the very first selection available from the 'displays menu item' (when connected to a display) it also has a simple shortcut (command+f1).
Anyways, good work!
@Chris_Hafner Thanks for checking out the code! Actually I totally know what you mean as it is such a basic task to just go in there and switch it. But since a lot of our professors are old...(no way to put it better) they really don't how to do it and don't really want to learn. Also doesn't help that our buildings are mainly PC houses. So when they have to walk in to to a mac based room they are just confused with looking at a Mac.
Also good point. I was gonna make a basic script where clicking an app would just call the keyboard shortcut and do the mirror swap, but apparently mac doesn't allow the Command button to be inputted into bash/terminal. Sucks.
Yes, totally understood. And I agree that pulling the executable down and packaging it up for deployment is the way to go. Github links sometimes break, projects get moved, etc.
As for keyboard shortcuts and all that, it IS possible to do Command + <something> calls, but it requires AppleScript to do it. And you may run into accessibility problems now that the OS tries to block those kinds of things until they are manually approved. So not really the way to go there unfortunately.