Jump to content

Please help me with close and open app script


Recommended Posts

Hello, everyone! I'm trying to write a script to close specific app (if it open) and open specific app (if it doesn't open) but fail every time.

 

What I do:

 

1. create NSAppleScript

2. Script:

on alfred_script(q)
  if application "Tunnelblick" is running then
  tell application "Tunnelblick" to quit
end if
end alfred_script

 

What I get:

[20:40:12.767] ERROR: VPN Toggle[Run NSAppleScript] {
    NSAppleScriptErrorAppName = Tunnelblick;
    NSAppleScriptErrorBriefMessage = "Not authorized to send Apple events to Tunnelblick.";
    NSAppleScriptErrorMessage = "Not authorized to send Apple events to Tunnelblick.";
    NSAppleScriptErrorNumber = "-1743";
    NSAppleScriptErrorRange = "NSRange: {103, 4}";

 

 But with Telegram it works! Why I can't quit Tunnelblick but can quit Telegram?

 

 

Link to comment

Look into System Settings → Privacy & Security → Automation. You probably haven’t allowed Alfred to control Tunnelblick there.


But don’t use NSAppleScript for this, use a Run Script with /usr/bin/osascript (AppleScript) as the language, like NSAppleScript itself suggests right at the top.

 

Alternatively, there are Automation Tasks for this.

 

Edited by vitor
Link to comment
49 minutes ago, vitor said:

Look into System Settings → Privacy & Security → Automation. You probably haven’t allowed Alfred to control Tunnelblick there.


But don’t use NSAppleScript for this, use a Run Script with /usr/bin/osascript (AppleScript) as the language, like NSAppleScript itself suggests right at the top.

 

Alternatively, there are Automation Tasks for this.

 

Thank you very much, now Alfred asks Tunnelblick privacy.

 

Maybe you can help me with script writing? I tried myself this:

 

on run argv
if application "Tunnelblick" is not running then
  open application "Tunnelblick"
if application "Tunnelblick" is running then
  tell application "Tunnelblick" to quit
end if
end run

 

Got this:

 

[22:04:29.459] ERROR: VPN Toggle - COPY[Run Script] /Users/****/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/4435190E-A2DA-4424-9016-AB038A46DFB6:191:194: script error: Expected “if”, etc. but found command name. (-2741)

 

I need this: if Tunnelblick is not running then open it, but if it's already running then quit it.

Edited by sosaveme
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...