Hi all
I wrote a small applescript that connects/disconnects my VPN connection. I saved it as an app and added it to Plex. It works quite well on the whole, and I’m happy to share it if anyone is interested.
My next goal is to run this less disruptively. I added growl notifications to provide success feedback while plex is full screen, but of course Plex automatically closes and re-launches once the script completes.
Is there any way to stop plex from closing when the app is launched?
Save this applescript as an application:
tell application “System Events”
tell current location of network preferences
set vpnStrong to service “ActivateVPN” – name of VPN
set isConnected to connected of current configuration of vpnStrong
if isConnected then
if exists vpnStrong then disconnect vpnStrong
– Check if Growl is running:
tell application “System Events”
set isRunning to ¬
(count of ¬
(every process whose name is “GrowlHelperApp”)) > 0
end tell
–Only display notifications if Growl is running:
if isRunning = true then
tell application “GrowlHelperApp”
– Make a list of all the notification types
– that this script will ever send:
set the allNotificationsList to ¬
{“Ansluten”, “Frånkopplad”}
– Make a list of the notifications
– that will be enabled by default.
– Those not enabled by default can be enabled later
– in the ‘Applications’ tab of the growl prefpane.
set the enabledNotificationsList to ¬
{“Ansluten”, “Frånkopplad”}
– Register our script with growl.
– You can optionally (as here) set a default icon
– for this script’s notifications.
register as application ¬
“Växla VPN” all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application “System Preferences”
– Send a Notification…
notify with name ¬
“Frånkopplad” title ¬
“VPN” description ¬
“Frånkopplad VPN” application name “Växla VPN”
end tell
end if
else
if exists vpnStrong then connect vpnStrong
– Check if Growl is running:
tell application “System Events”
set isRunning to ¬
(count of ¬
(every process whose name is “GrowlHelperApp”)) > 0
end tell
–Only display notifications if Growl is running:
if isRunning = true then
tell application “GrowlHelperApp”
– Make a list of all the notification types
– that this script will ever send:
set the allNotificationsList to ¬
{“Ansluten”, “Frånkopplad”}
– Make a list of the notifications
– that will be enabled by default.
– Those not enabled by default can be enabled later
– in the ‘Applications’ tab of the growl prefpane.
set the enabledNotificationsList to ¬
{“Ansluten”, “Frånkopplad”}
– Register our script with growl.
– You can optionally (as here) set a default icon
– for this script’s notifications.
register as application ¬
“Växla VPN” all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application “System Preferences”
– Send a Notification…
notify with name ¬
“Ansluten” title ¬
“VPN” description ¬
“Ansluten till VPN” application name “Växla VPN”
end tell
end if
end if
end tell
end telll
Then add it to your application list in Plex or add this line to your Harmony keymap if you using that:
Plex.RunAppleScript(tell application “ActivateVPN” to activate)
Make sure that Growl has the option “launch at startup” checked because sometimes the notification didn’t work if this option wasn’t enabled.
Just to be clear - I already wrote a similar application and am launching it in the same manner. I am asking if there is a way to run it without it closing/re-opening Plex.
Sorry, my bad...
Are you using some kind of remote eg. Harmony?
No - most frequently I use my bluetooth keyboard or use teleport from my macbook. I do have a keyboard shortcut set up, but it isn’t picked up when plex is running full screen.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.