Questions tagged [osascript]

MacOS command line tool which executes OSA scripts (AppleScript, JavaScript, etc.)

267 questions
3
votes
2 answers

Multiline strings in osascript

I want to do this in bash: read -r -d '' script <<'EOF' echo 1 echo 2 echo 3 EOF osascript -e "do shell script \"$script\" with administrator privileges" # Output: 3 # Expected: 1 # 2 # 3 Only the last line is executed. However, if I do…
Tyilo
  • 28,998
  • 40
  • 113
  • 198
3
votes
1 answer

Compile AppleScript into application with parameters

There is an AppleScript method: on displayError(theErrorMessage) display dialog theErrorMessage return "done" end displayError I wanna compile this script with passing parameter into (not run it with osascript!)My_Application.app something…
user3650408
  • 139
  • 1
  • 12
3
votes
1 answer

Select a particular tab in terminal depending upon the content using applescript and best practices

This is an application specific problem. I am trying to find and select a tab in Terminal.app depending on contents within. Here is what I'm doing: tell application "Terminal" set foundTabs to (every tab of every window) whose contents…
umop
  • 2,122
  • 2
  • 18
  • 22
3
votes
1 answer

How & where to best retrieve sudo password via a native GUI on a macOS Python-based app - (while maintaining an interactive output stream (stdout))

Ok, so the situation is this: I am building a macOS GUI App using Python and wx (wxphoenix). The user can use the GUI (say: script1) to launch a file-deletion process (contained in script2). In order to run successfully script2 needs to run with…
Montmons
  • 1,416
  • 13
  • 44
3
votes
0 answers

Node.js open terminal window (Electron on Mac OS)

I have an electron application that I would like to open a terminal (cmd window), and run a script within the terminal on the click of a button. I have tried a few options such as var spawn = require("child_process").spawn; However this only runs…
3
votes
1 answer

Execute ssh shell script from npm command

I'm trying to write an npm script that will execute an ssh shell command. Currently it's working by executing an osascript command to open a Terminal window and run the command. I'd like to change this to execute the command in the current…
Ethan22
  • 747
  • 7
  • 25
3
votes
0 answers

How to access chat properties in Messages with osascript for OS X 10.11?

After upgrading to OS X 10.11 El Capitan I have problems accessing properties of chats in the Messages app using osascript. It is easiest shown in the Terminal using javascript in osascript interactive mode but occurs as well in file-based scripts,…
Harry
  • 103
  • 7
3
votes
1 answer

OSX script to open a new iTerm window and run a command based on a variable

I am trying to use the iTerm example shown here in answer to another query. Basically I have a list of about 20 text files representing reports from different servers. I want to read each file name in the directory they live in and from that build a…
user3169632
  • 43
  • 1
  • 4
3
votes
1 answer

creating osascript one-line scripts, on mac osx 10.10.2

I'm new to terminal scripts and I'm trying to convert osascript -e 'tell app "Terminal" do script "ssh -t jgreen@dev-jgreen-bs pwd" end tell' This works with multiline as so but I want a one-line script, but I can't quite get it right. I keep…
3
votes
1 answer

Automation Script to record the screen with QuickTime using JavaScript

I'm trying to write a JavaScript Automation script for recording the screen on my Mac. I'm finding that the API is broken at the line that is doc.close(). QuickTime just hangs there and eventually my Script Editor fails with a timeout error. var…
3
votes
1 answer

How do you start an application in JavaScript via 'osascript'?

How do you start an application in JavaScript via osascript? I have been playing around with some of the examples, which can be found on the Internet and I can get them to work, but if an application targeted for automation is not already started I…
jonasbn
  • 183
  • 4
  • 11
3
votes
1 answer

javascript for automation [open location in finder]

I am trying to figure out how JXA(JavaScript for Automation) works, so try to translate a simple applescript as below to JXA. tell application "Finder" open location "smb://XXXXXXXX" end tell what I tried is here: finder =…
Cyrus Ngan
  • 199
  • 1
  • 6
3
votes
1 answer

Elevate your java app as Admin privilege on MAC OSX by osascript

I need your help to know where is my error please :) public class Main extends JFrame{ public Main() { EventQueue.invokeLater(new Runnable() { public void run() { setVisible(true); } }); …
Romain-p
  • 518
  • 2
  • 9
  • 26
3
votes
2 answers

Can't do shell script with a repeat with i from 1 to n loop

This works (prints, for example, “3 arguments”): to run argv do shell script "echo " & (count argv) & " arguments" end run This doesn't (prints only “Argument 3: three”, and not the previous two arguments): to run argv do shell script "echo…
Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
3
votes
1 answer

Osascript always returns error Cannot find executable for CFBundle 0x7fa3f42032e0

Osascript in terminal always returns this error for the simplest function. When i run the script in ApplescriptEditor it runs fine… e.g.: $: osascript -e 'tell application "iTerm" to display dialog "Hello World"' 2014-01-22 11:59:19.822…
Florian
  • 55
  • 3
1 2
3
17 18