applescript

How do I make a Safari window active using AppleScript (elegantly)?

☆樱花仙子☆ 提交于 2019-12-10 11:16:51
问题 While one can simulate command-shift-` using System Events to change windows in Safari, is there no better way to do this with AppleScript? I can change the index of Safari's windows, this changes their ordering on the screen but does not make them active. Suppose you have two Safari windows containing about:blank -- how could you bring the one in the back to the front and make it active? Granted, command-shift-` works, so maybe there only needs to be one way to skin this cat. 回答1: I also

Send email from clipboard without opening mail.app

佐手、 提交于 2019-12-10 11:09:27
问题 I searched for how to send email without opening apple mail, and found the question AppleScript - How to send a email without the mail app opening up However, I'm doing this with Keyboard maestro, so that I can send a specific email using a hot key in any application. After googling for the solution I found this script that does the job well: tell application "Mail" set theNewMessage to make new outgoing message with properties {subject:"hello", content:"You got a new file in your Downloads

Clicking an applications menu bar item with AppleScript

老子叫甜甜 提交于 2019-12-10 11:05:35
问题 I use Time Tracker For Mac as my, well, time tracker. It has a menu bar item which I want to be able to access via keyboard shortcut. I found a way to click the item with GUI scripting: tell application "System Events" to tell process "Time Tracker" click menu bar item of menu bar 2 end tell Unfortunately the script does not return success unless I acted on the menu (i.e. pressing Enter or Esc key). So if I want to trigger the down arrow key... tell application "System Events" to tell process

Extracting File Extensions from AppleScript Paths

白昼怎懂夜的黑 提交于 2019-12-10 10:59:49
问题 I'm writing an Apple Script that ultimately will mark commercials for all iTunes exports from EyeTV. But I'm running into a simple problem with AppleScript paths, which the EyeTV app returns as recording locations. Here's the context: set recordingID to 370404006 set myid to recordingID as integer tell application "EyeTV" set eyetvr_file to get the location of recording id myid as alias end tell return eyetvr_file alias "Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6

Get a list of all shortcuts from another application

不想你离开。 提交于 2019-12-10 10:56:16
问题 I'm wondering if there's a straightforward way of getting a list of all keyboard shortcuts present in the menubar of an other application (if possible also from closed applications). I'd like to use this in a simple Python application that I'm writing to simplify the process of configuring my Wacom-tablet for different applications. It doesn't really need to be a "clean" solution, I'm happy if I can just get the list produced once and then read it into my program. I've fiddled with

Optional parameters in AppleScript handlers

我的梦境 提交于 2019-12-10 09:26:10
问题 The Applescript documentation says that as of Yosemite, parameters for handlers can be made optional. From the section 'Parameter Specifications': Labeled parameters may be declared with a default value by following the formal parameter name with :literal. Doing so makes the parameter optional when called. For example, this declares a make handler with a default value for the with data parameter: on make new theClass with data theData : missing value This handler can now be called without

AppleScript 入门

懵懂的女人 提交于 2019-12-10 02:13:13
前言 AS 是能够帮你在 mac 上实现自动化的有效工具,他通过类英语的语法,以及简单的编程功能,帮助你摆脱机械化的劳动。 AppleScript 包括如下三部分: AppleScript 语言 AppleScript 脚本文件 AppleScript 脚本解释器 工具 在 mac 中自带 Automator 和 AppleScript Editor 均可以编写脚本。其中 Automator 是可视化工具,但功能更基础(似乎连循环都没有)。 一些 AppleScript 的脚本样例 Hello World tell current application display dialog "Hello World." end tell Hello * tell current application set str to "xp" display dialog "Hello " & str end tell Empty the trash tell application "Finder" empty the trash beep end tell Say Hello say "How are you?" using "Zarvox" say "Find, and you?" using "Victoria" say "Me, too." using "Zarvox" beep

tell application - string vs. string?

心不动则不痛 提交于 2019-12-09 23:42:33
问题 If I run: tell application "Maps" set miniaturized of windows to false end tell ...this works fine Yet, when I run: set applicationName to "Maps" tell application applicationName set miniaturized of windows to false end tell ...I get: Maps got an error: Can’t make |miniaturized| of every window into type reference. I also tried: tell application (applicationName as string) ... end tell ...but I get the same error. I'm new to Apple Script and not quite understanding the nuances between the two

How to use Applescript to Change Preference Pane Slider value?

断了今生、忘了曾经 提交于 2019-12-09 23:33:47
问题 I'm trying to create an AppleScript for setting the value of Input Volume of the Input category under the Sound menu in System Preferences . How does one change the value of a Slider? tell application "System Preferences" activate set current pane to pane "com.apple.preference.sound" end tell tell application "System Events" if UI elements enabled then try tell application process "System Preferences" tell tab group 1 of window "Sound" click radio button "Input" select row 1 of table 1 of

How to customise notification in os x using applescript

孤街浪徒 提交于 2019-12-09 19:18:36
问题 Say I have a file sometext.txt . I want the contents of this txt file to show up in the notification which I will trigger using displaynotification in applescript . In other words I want to be able to: display notification "File's content" with title "Title" . How can I do it? Assume that sometext.txt and the applescript file are in the same directory. 回答1: GOAL To fire a notification with text from a file that resides in the same folder as this script. NOTE Before execution, save the script