applescript

Attach event listeners in OS X JavaScript for Automation (JXA)

血红的双手。 提交于 2019-12-07 08:34:18
问题 How is it possible to listen for events in OS X JavaScript for automation. In the scripting Library for the Messages application there is a list of event handlers, such as messageSent and messageReceived . However, I cannot figure out how to use them. Trying to pass a function yields an error, and trying to set these variables to new functions causes the REPL to hang. What is the proper way to set up these event handlers? 回答1: You would create a script that you then select from the

Applescript to add an audio file to keynote and upload the file to youtube

為{幸葍}努か 提交于 2019-12-07 07:49:23
问题 I am trying to use either automator or applescript to do two things. add an mp3 to an open keynote presentation (to the entire presentation and not a single slide) upload the resulting keynote presentation to youtube. If I use the add file command, as below it doesn't seem to work, although if i replace slideshow with slide 1, then it adds it to slide 1 only. Thanks very much. tell application "Keynote" tell slideshow 1 add file slideshow 1 path theFile end tell end tell 回答1: You basically

Native caret position macos cocoa

给你一囗甜甜゛ 提交于 2019-12-07 06:59:10
问题 I want to be able to get the global caret position inside any application in Mac High Sierra using cocoa or appleScript. I already use NSEvent to get the keyboard and mouse hook but is there a way to get the caret position hook? The caret is different from the mouse position. It moves on key event or mouse click. In windows, you can get the caret position almost anywhere. I want to know if there is the equivalent for macos. I want to show a popup over the text caret, if i type on the keyboard

Implementing keyboard volume control buttons in Applescript - setting volume inside loop doesn't work

纵然是瞬间 提交于 2019-12-07 06:41:39
问题 Background I have a MacAlly IceKey keyboard. This keyboard has volume buttons that require a driver to function. This driver has not been updated since 2006, and I suspect it as the source of a recent spat of recurring kernel panics I've been experiencing under Mac OS X 10.6.1. So, out it goes; but I want my volume keys back! Using the wonderful ControllerMate, I can program these keys to do anything, including run an applescript script. So, I'm trying to implement that functionality. The set

Check for active internet connection with Applescript/Automator

て烟熏妆下的殇ゞ 提交于 2019-12-07 04:56:10
问题 I have an Automator workflow to ping a server, and download the latest copy of a schedule that I frequently use. This schedule then is copied to my dropbox so I can view it on my phone. Before the workflow downloads the newest schedule it deletes the old schedule from dropbox. This works well, except when I don't have an active internet connection. When I don't have an active internet connection, the workflow will still open up dropbox, delete the old schedule, and try to download the newest

AppleScript or Automator to click on menus in an application?

旧巷老猫 提交于 2019-12-07 04:37:37
问题 I'm not sure if this is do-able via AppleScript and/or Automator…but I'd like to be able to: a) launch an application (I know this can be done pretty easily by AppleScript or Automator) b) once the application is launched, use AppleScript or Automator to select specific menu items. e.g. I'd like to launch Excel 2008 (I have the home/student edition which doesn't come preconfigured for Automator) and then click the "File" menu and click on "open". Any pointers on where to go/look for how to

How do I set Mac OS X 10.6 Terminal tab title programmatically?

左心房为你撑大大i 提交于 2019-12-07 04:26:21
问题 I'm trying to learn Applescript as I'd like to, eventually, programmatically set the title of the tab in Terminal to whatever context I'm currently working in. Should be a simple task and I've gotten it almost right I think. This is my experimental code so far... tell application "Terminal" activate set frontIndex to index of the first window whose frontmost is true tell window frontIndex set title displays custom title of selected tab to true set custom title of selected tab to "Bazzy" end

Using AppleScript to choose a file in Safari

淺唱寂寞╮ 提交于 2019-12-07 04:23:00
问题 I am trying to write some automation code (primarily in Ruby Selenium). At some point, a file chooser is opened in Safari so that the user can select a file for upload. Selenium cannot handle this, but I think AppleScript should be able to. I am new to AppleScript and haven't been able to find any boilerplate code of someone automating a file chooser dialog. I'm reading through the AppleScript docs, but any ideas would be most helpful. 回答1: Some more searching and I found a great answer here:

How can I identify the current terminal emulator from a bash script?

ぐ巨炮叔叔 提交于 2019-12-07 02:46:51
问题 I've got a script that will open a new tab in the OS X Terminal application and I'm trying to add support for iTerm2. Unfortunately, the methods to open tabs in the two terminal emulators are different. How could I tell which of the two is being used, or is open, to conditionally run the correct script? 回答1: I'm not sure how to tell iTerm and iTerm2 apart, but check the $TERM_PROGRAM envar. For me (Mac OS X 10.7), it returns Apple_Terminal for Terminal.app , and iTerm.app for iTerm2. 回答2: You

change screen resolution with AppleScript

谁都会走 提交于 2019-12-06 22:52:28
I am trying to click at radio buttons in Displays panel of System Prefernces, namely to change Screen resolution. This is the code I use to identify radio buttons: tell application "System Preferences" activate reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays" end tell tell application "System Events" tell application process "System Preferences" set frontmost to true get every radio button of window 0 --click button 1 of window 0 of application process "System Preferences" of application "System Events" --click radio button "Scaled" of radio group of window "com