Created
September 22, 2015 17:04
-
-
Save sodacrackers/bab6ca79103838b3958c to your computer and use it in GitHub Desktop.
Mac 10.10 Mac Yosemite - Parallels Desktop OS Chooser Login Items Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- From Mac ScriptEditor, export as "Application" and add to startup items | |
set os_mac to "Mac" | |
set os_windows to "Windows 7" | |
set os_choice to os_mac | |
set os_windows_image to POSIX file "/Users/Shared/Parallels/Windows 7.pvm" | |
set log_file to "/log.txt" | |
activate | |
logMessage("Paralles Desktop chooser activating") | |
on promptOsChoice() | |
global os_mac, os_windows, os_choice | |
tell me to activate | |
set os_prompt to display dialog "Welcome!" & return & return & "On this computer, you can choose to use either Mac or Windows." & return & return & "Please choose an operating system." with icon alias ((path to me) & "::" & "uw_logo.icns" as string) buttons {os_mac, os_windows} default button 1 giving up after 30 | |
set no_response to (gave up of os_prompt) | |
set os_choice to button returned of os_prompt | |
if (no_response is not true) and (os_choice is equal to os_windows) then launchWindows() | |
end promptOsChoice | |
on launchWindows() | |
global os_choice, os_windows, os_windows_image | |
do shell script "sleep 2s" | |
tell application "Finder" | |
open os_windows_image | |
end tell | |
restartWhenClosed() | |
end launchWindows | |
on restartWhenClosed() | |
-- Reboot if Parallels is not running | |
-- Set Parallels Desktop preferences to close on shutdown | |
global os_windows | |
repeat | |
-- delay here so Windows may start | |
do shell script "sleep 12s" | |
tell application "System Events" | |
if (exists of application process os_windows) is false then | |
restart | |
return | |
end if | |
end tell | |
end repeat | |
end restartWhenClosed | |
on logMessage(message, clear_log) | |
global log_file | |
if (clear_log is not false) then do shell script "echo '' > " & log_file & "" | |
set log_message to date string of (current date) & "|" & time string of (current date) & "|" & message | |
do shell script "echo '" & log_message & " ' >> " & log_file & "" | |
end logMessage | |
-- Prompt for OS Choice and launch Parallels Desktop Windows | |
promptOsChoice() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment