applescript

Script to play a warning when battery level is under a threshold in MacOS

淺唱寂寞╮ 提交于 2019-12-07 17:25:00
问题 I am using a MacBook and the battery is unreliable. I am trying to find a script command that will enable the laptop to play a beep when the battery level is lower than a threshold. After some search and tests, I found a quick solution below: 1) I first create a file called check_battery with the following contents: ioreg -l | awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.3f";max=c["\"MaxCapacity\""]; bat= (max>0?100*c["\"CurrentCapacity\""]/max:"?"); printf("%d", bat)}' 2) I then created the

How Can I Pass a String From Applescript to Objective C

允我心安 提交于 2019-12-07 15:03:51
问题 I'm working on an application where I need to be able to pass a string variable from Applescript to Objective C . I have figured out how to run Applescript from a method in my Objective C Class, but I need to be able to set an NSString to a string from Applescript . How would I be able to accomplish this? Thanks in advance! 回答1: Quick example: NSString *theScript = @"set theTimeString to time string of (current date)\n" "return theTimeString"; NSDictionary *errorInfo = nil; NSAppleScript *run

Applescript file dialog with UI scripting

匆匆过客 提交于 2019-12-07 12:56:31
问题 I am trying to open a file in a not so scriptable area of an application. I got halfway there by using UI scripting to select the proper menu item, but this opens a standard file dialog. How can I set the destination of the file dialog with Applescript? 回答1: ahh ok this should get you going on the right path tell application "Safari" activate -- do menu select gui script first set posixpath to "/path/to/a/folder/that/exists" tell window 1 tell application "System Events" keystroke "g" using

applescript and terminal ( run several do shell script in one terminal window )

回眸只為那壹抹淺笑 提交于 2019-12-07 12:21:14
问题 I do have several shell scripts whom are get activate not really behind each other. But I want to stay in the same terminal window. To simplify the problem, lets say that as example first script. - cd to the working directory second. - do some things and get files from that directory third. - dome more thing on the newly files/folders in that directory. fourth. - .... How can I let script 2 and 3 ( all the script thus ) run in that very same directory and window that is opened during script 1

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

Applescript to open an application in full-screen mode?

偶尔善良 提交于 2019-12-07 11:05:13
问题 I'm trying to program Alfred to open my Terminal, Sublime Text, and Chrome with a workflow. I would like for my terminal to open normally as a window, but I've been trying to get Chrome and Sublime to open full screen. I was able to get Chrome to open up in full screen mode with: on alfred_script(q) tell application "Google Chrome" tell window 1 to enter presentation mode end tell end alfred_script However, this did not translate to work with my Sublime Text. What am I missing here? 回答1: As

Xcode debugging AppleScript

你。 提交于 2019-12-07 10:45:25
问题 Xcode has apparently AppleScript debugging facilities : You can put breakpoints Executable options mentions AppleScript Debugger But I could not figure how to Run & Debug script... Tried setting up a custom executable calling osascript with script as argument, breakpoints are not hit. Any ideas? 回答1: I'm in a similar position. I'm new to XCode and have successfully followed the "Hello World" tutorial which includes guidance for debugging. I then created a Project based on Cocoa-Applescript

get bounds of desktop with applescript

五迷三道 提交于 2019-12-07 09:41:20
问题 I'm trying to get the bounds of my desktop window by using applescript with the following code: tell application "Finder" get bounds of window of desktop end tell I keep getting "execution error: Finder got an error: Can’t get bounds of window of desktop. (-1728)". I'm running Lion. Any idea how I can get this to work? 回答1: The Desktop and a window are two different things. The Desktop is actually a folder located at Macintosh HD:Users:yourusername:Desktop: . If you mean that you want to get

How to run a python script inside Applescript?

谁都会走 提交于 2019-12-07 09:23:19
问题 I had to do an Applescript and by the end of it i just want to run a python script. I wrote do shell script "/Users/Tom/Desktop/ayscript.py" But it's said "permission denied" Any idea ? 回答1: You are trying to run the script directly instead of using Python to run it. You need to do shell script python , passing the path to your script as an argument. do shell script "python /Users/Tom/Desktop/ayscript.py" 来源: https://stackoverflow.com/questions/23108335/how-to-run-a-python-script-inside

How to find whether a certain bluetooth device is connected?

半城伤御伤魂 提交于 2019-12-07 09:10:13
问题 I want to use applescript to do a periodic (every second) check to see if a specific bluetooth devices is connected, and if so, to flash up a quick notification. To frame it, I want a popup when my Airpods connect, since sometimes when I pull them out, the connect to my computer, and sometimes to my iPhone. I've got everything figured out, except for the bluetooth check part. I've used this as a starting point, but can't get it to work. Any help would be appreciated. repeat set statusOld to