osascript

How do you run inline Applescript from a JXA/JavaScript for Automation script on macOS?

断了今生、忘了曾经 提交于 2019-11-30 21:17:45
问题 I have a script written in JavaScript which needs to run one small piece of AppleScript (to achieve some functionality I've been unable to implement due to a number of factors natively in JS). It should be able to take a single string argument, and is pretty much a tell-endtell one liner. Is it possible to assemble this nanoprogramme as a string in JavaScript then pass the string to the AppleScript environment for execution, and how would that be done? There's plenty of explanations online

How do I simulate a mouse click through the mac terminal?

一世执手 提交于 2019-11-30 08:59:59
Is there any way to do this without any programs or scripts? (Maybe through osascript?) davidcondrey You can automate a mouse click using Applescript. tell application "System Events" tell application process "Application_Name" key code 53 delay 1 click (click at {1800, 1200}) end tell end tell If you want to click within a browser window you can use Applescript with the help of Javascript tell application "safari" activate do JavaScript "document.getElementById('element').click();" end tell Purely via terminal, you can create a textfile with the name click.m or whatever name you like, save it

How do I simulate a mouse click through the mac terminal?

不想你离开。 提交于 2019-11-29 13:22:22
问题 Is there any way to do this without any programs or scripts? (Maybe through osascript?) 回答1: You can automate a mouse click using Applescript. tell application "System Events" tell application process "Application_Name" key code 53 delay 1 click (click at {1800, 1200}) end tell end tell If you want to click within a browser window you can use Applescript with the help of Javascript tell application "safari" activate do JavaScript "document.getElementById('element').click();" end tell Purely

How to check in AppleScript if an app is running, without launching it - via osascript utility

与世无争的帅哥 提交于 2019-11-27 06:27:32
Consider the following AppleScript: on is_running(appName) tell application "System Events" to (name of processes) contains appName end is_running set safRunning to is_running("Safari") if safRunning then tell application "Safari" -- Stuff I only want executed if Safari is running goes here. end tell return "Running" else return "Not running" end if The problem: when I run this via the osascript command line utility, if Safari is not running, it gets launched and the script reports "Running". This is not the behaviour I desire or would expect. Note that it works as desired/expected when run

Combining variables in Bash to form a command sent to AppleScript using the osascript command

随声附和 提交于 2019-11-26 20:43:34
问题 I'm trying to make this script work. It's a Bash script that is meant to take some variables, put them together and use the result to send an AppleScript command. Manually pasting the string echoed from the variable to_osa behind osascript -e to the terminal works as I want and expect it to. But when I try to combine the command osascript -e and the string to_osa , it does not work. How can I make this work? the_url="\"http://stackoverflow.com/questions/1521462/looping-through-the-content-of

How to check in AppleScript if an app is running, without launching it - via osascript utility

偶尔善良 提交于 2019-11-26 12:00:30
问题 Consider the following AppleScript: on is_running(appName) tell application \"System Events\" to (name of processes) contains appName end is_running set safRunning to is_running(\"Safari\") if safRunning then tell application \"Safari\" -- Stuff I only want executed if Safari is running goes here. end tell return \"Running\" else return \"Not running\" end if The problem: when I run this via the osascript command line utility, if Safari is not running, it gets launched and the script reports

osascript using bash variable with a space

吃可爱长大的小学妹 提交于 2019-11-26 09:43:21
问题 I am using osascript in Bash to display a message in Notification Center (Mac OS X) via Apple Script. I am trying to pass a text variable from Bash to the script. For a variable without spaces, this works just fine, but not for one with spaces: Defining var1=\"Hello\" var2=\"Hello World\" and using osascript -e \'display notification \"\'$var1\'\"\' works, but using osascript -e \'display notification \"\'$var2\'\"\' yields syntax error: Expected string but found end of script. What do I need