sosaveme Posted December 10, 2022 Share Posted December 10, 2022 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
vitor Posted December 10, 2022 Share Posted December 10, 2022 (edited) 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 December 10, 2022 by vitor Link to comment
sosaveme Posted December 10, 2022 Author Share Posted December 10, 2022 (edited) 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 December 10, 2022 by sosaveme Link to comment
vitor Posted December 10, 2022 Share Posted December 10, 2022 Use the Automation Tasks, under the macOS group there are tasks for this. The error is that your second if needs to be an else if. Also, you don’t need the on run as you’re not using arguments. Link to comment
sosaveme Posted December 10, 2022 Author Share Posted December 10, 2022 Thanks! Everything is working. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now