Last active
March 7, 2017 13:10
-
-
Save OliverJAsh/4192132 to your computer and use it in GitHub Desktop.
AppleScript to launch a network drive prior to launching an application. Useful if your iTunes or Aperture library is stored remotely.
This file contains 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
# Options | |
set networks to {"YOUR_SSID"} | |
set diskName to "YOUR_DISK_NAME" | |
set mountPath to "afp://192.168.0.2/" & diskName | |
set applicationName to "YOUR_APPLICATION_NAME" | |
# Get wireless network SSID | |
set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'" | |
# Test if we are connected to the right network(s) | |
if SSID is not in networks then | |
# If we are not connected to the right network(s), throw an error | |
display dialog "You are not connected to your home network." | |
return | |
end if | |
tell application "Finder" | |
try | |
# Mount the disk | |
mount volume mountPath | |
on error | |
# A network error will already be shown to the user | |
return | |
end try | |
# Hold up the script until we can be sure the disk has successfully mounted | |
set i to 0 | |
repeat until (name of every disk contains diskName or i is greater than 10) | |
delay 1 | |
set i to i + 1 | |
end repeat | |
# Check that the disk successfully mounted | |
if exists disk diskName then | |
# If the disk successfully mounted, launch the application | |
tell my application applicationName | |
# Launch launches, activate brings window to focus (?) | |
launch | |
activate | |
end tell | |
else | |
# If the disk didn’t mount for some reason, throw an error | |
display dialog "Unable to connect to iTunes storage device." | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment