osascript

How to get POSIX path of the current script's folder in JavaScript for Automation?

心不动则不痛 提交于 2019-12-18 05:05:16
问题 In AppleScript it’s possible to get the the POSIX path of the folder the current script is located in using this line: POSIX path of ((path to me as text) & "::") Example result: /Users/aaron/Git/test/ What’s the JavaScript equivalent? 回答1: Here's a way [NOTE: I NO LONGER RECOMMEND THIS METHOD. SEE EDIT, BELOW] : app = Application.currentApplication(); app.includeStandardAdditions = true; path = app.pathTo(this); app.doShellScript('dirname \'' + path + '\'') + '/'; note the single quotes

Trouble escaping quotes in a shell script

戏子无情 提交于 2019-12-13 14:57:23
问题 I have a bash script I am making that generates some numbers assignes them to variables then uses osascript to write them out in any application of choice. Here is a simplified version of what I want to do. monday1=5 osascript -e 'tell application "System Events" to keystroke "$monday1"'; \ The osascript should look like this osascript -e 'tell application "System Events" to keystroke "5"'; \ This will then type out the number 5 in what ever app I have my cursor in. The problem is it outputs

Why does this preinstall script just partly run?

牧云@^-^@ 提交于 2019-12-13 04:52:13
问题 I use PackageMaker to create an installation package. The following is my preinstall script to be called by Installer : #!/bin/sh /usr/bin/osascript <<EOF tell application "System Events" if exists (application process "Dictionary") then tell application "Dictionary" to quit end if end tell set theFolder to (path to library folder as text) & "Dictionaries:" set fileNames to {"dict1.dictionary", "dict2.dictionary", "dict3.dictionary", "dict_n.dictionary"} set dict to {} repeat with aFile in

How to close a Terminal tab using AppleScript?

瘦欲@ 提交于 2019-12-12 12:18:16
问题 I'm using AppleScript to open PostgreSQL in a Terminal tab like this: #!/bin/bash function new_tab() { TAB_NAME=$1 COMMAND=$2 osascript \ -e "tell application \"Terminal\"" \ -e "tell application \"System Events\" to keystroke \"t\" using {command down}" \ -e "do script \"printf '\\\e]1;$TAB_NAME\\\a'; $COMMAND\" in front window" \ -e "end tell" > /dev/null } new_tab "PostgreSQL" "postgres -D /usr/local/var/postgres" Running this script from the Terminal will open a new tab with PostgreSQL

osascript and sudo password entry

断了今生、忘了曾经 提交于 2019-12-12 04:56:36
问题 I am using osascript in a BASH script for dialog boxes on a MAC system. The problem I am having is several of the commands I need to use require privilages to function correct. If I use sudo in the BASH script, the password prompt shows in the terminal window. Is the some way I can hook the sudo password prompt into an osascript dialog box? Or is there a different way I can handle asking for the password in an osascript dialog box and passing it to some other program to handle it? 回答1: What

osascript set volume isn't working via ssh

假装没事ソ 提交于 2019-12-12 02:27:47
问题 here is my situation. User A is currently logged on Computer A . User B logs into Computer A via ssh. User B runs via terminal a osascript ( osascript -e 'set volume 0' ) here is my error log: Oct 20 13:25:17 osascript[29389] <Error>: Set a breakpoint at CGSLogError to catch errors as they are logged. Oct 20 13:25:17 osascript[29389] <Error>: This user is not allowed access to the window system right now. Oct 20 13:25:17 osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid

Compile AppleScript into application with parameters

与世无争的帅哥 提交于 2019-12-11 05:47:58
问题 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 like osacompile - o My_Application.app My_Script.applescript "This is error message as parameter" In this case, I will have compiled app which I can run. Looking for a command on how exactly to compile the script with passing parameters. As compilation

Java starting running command in new terminal (mac osx) - process builder not running osascript properly

穿精又带淫゛_ 提交于 2019-12-11 02:22:22
问题 I'm trying to create a new process in a new window. I'm following this example for the command Running a command in a new Mac OS X Terminal window (using Java Process builder). I printed out the resulting command and it works if I type it in manually, but it doesn't start the new window when I run it. Something as simple as osascript -e 'tell application "Terminal" to do script "java -jar test.jar"' doesn't bring anything up Sample code: try { ProcessBuilder pb = new ProcessBuilder("osascript

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

狂风中的少年 提交于 2019-12-07 20:18:35
问题 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 sudo rights. script2 will itterate over a long list of files and delete them. But I need it to communicate with the GUI contained in script1 after each round so that script1 can update the progressbar. In it's absolute most basic form my current

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

[亡魂溺海] 提交于 2019-12-07 11:50:43
问题 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 contains "selectme" repeat with possibleTab in foundTabs try set selected of possibleTab to true end try end repeat end tell This isn't acting as expected and is pretty foolproof. I wonder if someone can suggest a way to do this with much less code (for