Questions tagged [applescript]

AppleScript is a proprietary programming language in macOS to control and exchange data with applications.

AppleScript is a programming language used in macOS to control and exchange data with applications. Its main function is to automate repetitive tasks. AppleScript has some basic functionality of its own, but it mainly relies on other applications to accomplish its tasks. AppleScript has been incorporated into Apple's operating systems since OS 7, in 1993, as an outgrowth of the HyperCard project.

AppleScripts are useful ways to increase efficiency by performing repetitive duties. An example of this can be found in the "Trim File Names" script that is preloaded on macOS systems. Instead of going through file names and deleting chosen phrases by hand, this AppleScript performs a loop and accomplishes the job in several seconds.

The AppleScripting language is based on natural language to decrease the learning curve for AppleScripting. For instance, to display a window with the text "Hello World!" the code goes like this:

display dialog "Hello World!"

AppleScript was created to be easy to use, edit, and write, without learning a whole programming language.

There are several AppleScript editors, both paid and free. Script Editor (AppleScript Editor in macOS versions after Snow Leopard) is included with macOS. It includes syntax highlighting, result windows, and debugging tools. Xcode, which is included in the macOS Developer tools, provides more sophisticated AppleScripting with customizable graphical interfaces, and the ability to turn an AppleScript into a full-fledged application. Smile is a free third-part application that allows for line-by-line testing, and unicode windows. SmileLab is a commercial application developed by the Satimage, the makers of Smile. Script Debugger is another third-part application for AppleScript developing. Script Debugger includes some of the same features as Smile like line-by-line testing. It also includes an advanced application dictionary browser.

For further reading: http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptX/AppleScriptX.html

http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html

3425 questions
100
votes
8 answers

How do I assign a keyboard shortcut to an AppleScript I wrote?

How do I assign a keyboard shortcut to an AppleScript? I found a script for automatically going back to the inbox in Office 2011.
Tom
  • 1,017
28
votes
4 answers

How do I make an AppleScript file into a Mac App?

I have an Applescript that simply opens a Dialog Box, asks for a user input and runs a Terminal Command and spits out the answer. It works great in AppleScript Editor yet I am trying to work out how I could package this Script File along with an…
ChuckJHardy
  • 460
  • 1
  • 5
  • 9
26
votes
5 answers

How to know the name of UI elements using Accessibility inspector (or any other tool)

I'm trying to interact with a print dialog via Applescript. What I want to emulate is the user setting a value on a specific dropdown. Say I have: tell application "System Events" tell process "Preview" set value of pop up button XXX to YYY …
Roberto Aloi
  • 1,344
19
votes
3 answers

Why are Script Editor .scpt files not saved as plain text files?

The Script Editor (formerly AppleScript Editor pre-Yosemite 10.10) saves .scpt files as binary files, not plain text files. It makes working with them in source code control systems somewhat cumbersome. Does anyone know why this is the case? Is…
Ian C.
  • 45,969
17
votes
1 answer

How do I click a button using AppleScript?

I'm trying to press a button in TeamSpeak using applescript, here is my code: tell application "TeamSpeak 3 Client" to activate tell application "System Events" tell process "TeamSpeak 3" click menu item "Connect" of menu "Connections"…
16
votes
5 answers

How can I automatically launch an application whenever the Mac goes idle?

Is there a way to launch an application, such as Transmission, every time the computer goes idle (instead of sleeping)?
Petruza
  • 2,845
15
votes
1 answer

Applescript: Comparing variable to string is failing

I have an applescript that gets a list of items and then iterates over them: tell application "GeekTool Helper" set names to name of geeklets repeat with currentName in names if (currentName is equal to "Top_CPU_Processes") then …
11
votes
2 answers

How to change AppleScript path to a Terminal-style path?

I have a custom Service that I've created in Automater (I'm on OS X 10.6.5). The Service executes an AppleScript which in turn executes a shell script. Here is the AppleScript: on run {input, parameters} -- do shell script "/usr/bin/find " &…
11
votes
1 answer

Waiting until a window exists in Applescript?

I'm trying to work with the script below and the repeat until exists window "Print"loop never returns true (I never hear the beep 3). Is this the correct way to wait for a window to appear? I am using the Accessibility Inspector and this is the…
spring
  • 523
9
votes
2 answers

How do I make the mouse click at current location using AppleScript?

So I've been trying to make a program using AppleScript, but there's one thing that's been teasing me for some time now - How do I make the mouse click at current location without using Mouse Keys? Also, is it possible to simulate a long click (that…
Prokop Hanzl
  • 1,165
9
votes
1 answer

Why am I getting "Error -1,752" when trying to save in Script Editor?

I'm trying to edit a script in ~/Library/Scripts/Applications/Mail. When I attempt to save from Script Editor I get The document "Reply.scpt" could not be saved. (Error -1,752). It doesn't seem to be a permissions issue because I can edit and save…
SSteve
  • 2,756
8
votes
1 answer

How to use AppleScript to launch three scripts, each in new Terminal tab?

I'm trying to launch 3 tabs and run a script in each with AppleScript. So far I haven't been able to get this done. Currently I have: tell application "Terminal" activate do script "ping google.com" tell application "System Events" …
Nick
  • 83
8
votes
2 answers

How do I use AppleScript to reveal a file in Finder from its POSIX path?

I'm trying to create an AppleScript snippet that locates the current random wallpaper and reveals it in Finder. I have the following snippet which finds the current wallpaper's POSIX path as a string: set plistFolderPath to path to preferences…
Brant Bobby
  • 3,869
8
votes
5 answers

How do I make an AppleScript with a drop-down menu without Xcode?

How do I make an AppleScript that displays a drop-down menu without using Xcode?
daviesgeek
  • 38,901
  • 52
  • 159
  • 203
8
votes
3 answers

How can I trim the first 3 characters in file name with AppleScript?

Is there a way to trim off the first 3 character of multiple file names? (or last 3 characters)
daviesgeek
  • 38,901
  • 52
  • 159
  • 203
1
2 3
22 23