Questions tagged [applescript]

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

Filter by
Sorted by
Tagged with
95 votes
8 answers
105k views

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's user avatar
  • 967
398 votes
13 answers
238k views

How can I trigger a Notification Center notification from an AppleScript or shell script?

I'd love to be able to take advantage of 10.8's Notification Center features in AppleScripts and shell scripts I write. Is there a built-in command or a third-party library I can use from either an ...
Nathan Greenstein's user avatar
11 votes
5 answers
16k views

Using Apple Script to Manage Sound Output Selection

I am brand new here and I have an additional clarification or need additional help for an issue from this thread - Applescript: "can't get tab group 1 of window" (El Capitan) In my ...
JRTemp's user avatar
  • 111
112 votes
1 answer
242k views

How do I automate a key press in AppleScript?

Is it possible to automate the key press of a key (such as "a" or "<") in Mozilla Firefox, Google Chrome or Safari (in this order)? I'd like to automate the key press of "a" for example in Mozilla ...
Shoe's user avatar
  • 1,766
21 votes
11 answers
31k views

Is it possible to change display resolution with a keyboard shortcut?

I use different screen resolutions based on the activity I'm doing during the day. For example when I'm coding I prefer to have more space available. Is it possible to associate a keyboard shortcut to ...
david-e's user avatar
  • 313
9 votes
2 answers
40k views

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? ...
Prokop Hanzl's user avatar
  • 1,145
74 votes
2 answers
90k views

Run AppleScript from bash script

If I wanted to run an AppleScript from within a bash script I could call a file with the list of commands that I require to execute. #!/bin/bash {some commands} osascript file.scpt {other commands} ...
Danijel-James W's user avatar
0 votes
3 answers
1k views

Applescript Won't Invoke Shortcut Command

I have a long TextEdit document I frequently open (via a keystroke, thanks to Alfred). It contains many non-standard spellings, so I de-select "Check Spelling While Typing" (though I want spell ...
Jimmbo's user avatar
  • 9
31 votes
5 answers
14k views

How to programatically add folder to Spotlight "do not index"?

Is there any way to programmatically add a folder to Spotlight's "Privacy" tab? Either through Terminal or Applescript? Often I want to click on an item in Spotlight results in Finder, and have that ...
Dan's user avatar
  • 3,872
26 votes
5 answers
45k views

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 "...
Roberto Aloi's user avatar
  • 1,344
12 votes
4 answers
21k views

Script to raise a single window to the front

In a script I'm trying to find the Terminal.app window containing a specific tty device and raise that window to the top. Here's what I have in Applescript so far: tell application "System Events" ...
crowding's user avatar
  • 266
3 votes
4 answers
11k views

change screen resolution with AppleScript

How can I change change screen resolution using AppleScript? If AppleScript can't do it, what about Terminal? I tried with examples at How to set screen resolution with a keyboard shortcut on Retina ...
sanjihan's user avatar
  • 2,675
2 votes
2 answers
1k views

Move external iTunes library files to different location without losing metadata

I'm trying to move my iTunes library to a new location. I'm running iTunes without the "organize media" option because I keep my library (60000+ songs) on a second drive in my MacBook... I recently ...
Steven B.'s user avatar
  • 121
32 votes
15 answers
73k views

How to retrieve current wattage info on OS X?

Is there a way to retrieve the current watt usage info on OS X Snow Leopard? I'm using mid-2010 iMac, so I'm not looking for just battery-related apps. Does OS X even monitor power usage? Do I need to ...
Jari Keinänen's user avatar
20 votes
5 answers
44k views

Turn Wifi off/on with a single key?

Is there a way to assign the WiFi on/off function to one of the function keys like F4 that I otherwise never use? I assume Applescript would be required. However I may want to use a BASH script ...
Ebu's user avatar
  • 303
16 votes
5 answers
7k views

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's user avatar
  • 2,825
14 votes
7 answers
18k views

Using AppleScript to lock screen

I need an applescript which locks my Mac in the same way pressing shift+ctrl+eject would. I tried two different approaches, but both failed. The first one was to search the internet for a script, ...
Lavaking's user avatar
  • 161
11 votes
2 answers
26k views

How can I configure my computer to run an AppleScript at a specific time? Caveat: without using iCal

Since upgrading to Lion, I have seen a sleight decrease of productivity when it comes to using iCal. As a result, I am trying alternatives such as BusyCal. The application seems great, however I cant ...
finiteloop's user avatar
10 votes
4 answers
4k views

Applescript run from menu bar?

I am aware of the Script Editor menu. That is not what I'm looking for. Is there a way to run an Applescript from the menu bar? I can save it as a file and run it from the Script Editor menu, and I ...
DonielF's user avatar
  • 1,082
10 votes
4 answers
8k views

Programmatically/Script-atically changing the default Open-With setting

Is there a way to change what app opens a file type programmatically/with a script? Basically, sometimes I'm working on a web site, and I want to set all web files to open with a text editor (*.php, *...
Fake Name's user avatar
  • 5,389
7 votes
1 answer
6k views

Applescript: "can't get tab group 1 of window" (El Capitan)

The following is an applescript that I use to change audio output devices: tell application "System Preferences" activate set current pane to pane "com.apple.preference.sound" end tell tell ...
gdavtor's user avatar
  • 195
5 votes
2 answers
1k views

Is there a macOS equivalent of the Windows assoc command?

I am looking to change a file association on the Mac using some sort of script. I know that I can do something like that in Windows using the assoc command. Is there something scriptable on macOS ...
Manngo's user avatar
  • 3,415
4 votes
3 answers
2k views

Swap Mouse Button using AppleScript

I use mouse with left-hand. My system is shared with other people who are right handed. So, I need frequently to switch mouse button. I would like to know how to swap mouse button using AppleScript? ...
doptimusprime's user avatar
4 votes
1 answer
5k views

ffmpeg working from command line in Terminal but not in an Automator shell script!

I have just compiled my own copy of ffmpeg on my system and it's located in the following path: /opt/local/bin/ffmpeg When I run the following command in Terminal.app, it runs smooth: ffmpeg -i /...
TheLearner's user avatar
4 votes
2 answers
4k views

Need to automate an SMB path into a UNC path before sending to Win10 clients

New here, but I'm having difficulty putting together an AppleScript that will basically take an SMB link and turn it into a UNC link before I send it over to a couple of Win10 clients. All same ...
charmndr's user avatar
4 votes
2 answers
5k views

Run script before restart/shutdown

Is it possible to execute a script/command right before OS X is shutting down or restarting? I'd like to run sudo apachectl stop to stop apache from auto-starting.
Till's user avatar
  • 487
4 votes
2 answers
5k views

How can one invoke a keyboard shortcut from within an AppleScript?

I need to invoke a keyboard shortcut from within an AppleScript code, later to be used as a startup item (i.e. the alternative to having to press something at every log in).
Barton's user avatar
  • 41
2 votes
1 answer
2k views

Bash Script which calls osascript stops working when run by launchd

I am trying to troubleshoot a problem with a bash script that gets called by launchd. Here's a quick summary Calling the script manually by itself works fine with no errors. Within the bash ...
Allan's user avatar
  • 98.8k
18 votes
7 answers
7k views

Is there a bash command to check to see if Time Machine has finished backing up?

I'm writing a script that will rsycnc my Time Machine directory to a remote server using ssh. I've switched from a shell script to an AppleScript and then back to an Apple script and I don't really ...
whitneyz's user avatar
  • 193
16 votes
1 answer
5k views

What's the equivalent of "do shell script" with javascript automations? (Yosemite)

Support for javascript automations started with Yosemite. How could I run using javascript an external command? (i.e. the equivalent of do shell script of applescript?
GJ.'s user avatar
  • 1,224
12 votes
2 answers
16k views

macOS Sierra: AppleScript mount volume keeps asking for login

For several OS X versions I've used: /usr/bin/osascript -e mount volume "smb://yourserver" as user name "yourusername" with password “yourpassword” This has worked great, a nice and quiet mount of ...
Hanzaplastique's user avatar
10 votes
2 answers
22k views

Open terminal via AppleScript

I'm tring to write a shortcut script in spark for opening the terminal. on run {input, parameters} tell application "Utilities/Terminal" // tried Utilities:Terminal and Terminal too reopen ...
Thellimist's user avatar
9 votes
2 answers
14k views

Automating ffmpeg using Automator Service

I often use ffmpeg off the command line to convert video files into mp4 on my Mac (running Mavericks). Do note, however, that I am NOT re-encoding my videos; am just changing the container from an avi ...
TheLearner's user avatar
7 votes
3 answers
6k views

Right-click for Creating a New Document - How?

I am comfortable with creating new documents from command line on OS X (in my case El Capitan), but I wanted to explore the possibility to have Windows-like option to create a new document on right ...
panza's user avatar
  • 173
7 votes
2 answers
10k views

When MouseKeys are on, how do I click or move the mouse using AppleScript?

This post suggests that the command tell application “System Events” to key code 37 in AppleScript should move the mouse pointer one pixel down and to the left if run when MouseKeys are enabled. In OS ...
Daniel's user avatar
  • 34.6k
6 votes
4 answers
5k views

Automatically quit Terminal when typing exit

Scenario I use terminal to SSH a lot, however would like the Terminal App to quit when the last Tab closes using exit. I already have the terminal window itself set to close on successful exit, ...
BinaryMisfit's user avatar
  • 6,515
6 votes
3 answers
9k views

AppleScript – How can I _get_ UI elements' names, attributes, properties, classes programmatically without "guessing" via AccessibilityInspector?

When I started to search for an AppleScript's generic way to "click onto Safari's context menu" of a selected item, there were a lot of questions on "how-to" on several levels of nomenclature. How ...
clemsam lang's user avatar
  • 1,132
4 votes
1 answer
4k views

AppleScript Help: Wait for Safari Page to load

I am trying to create a script to open the URL csbsju.instructure.com in Safari, wait for the page to load all the way, click the login button, and then double check if the URL is correct (there's a ...
Andrew Breyen's user avatar
4 votes
1 answer
3k views

Automatically accept Screen Sharing invitations?

I use Messages' Ask to Share Screen feature all the time to remotely debug problems on my contacts' Macs. It's a very easy way to initiate a Screen Sharing session, does not require port forwarding, ...
pkamb's user avatar
  • 8,393
4 votes
1 answer
4k views

How to rework a "System Events" command in AppleScript, so that it automatically works in all applications?

With the following AppleScript code within a "Run AppleScript" action in a Service: tell application "System Events" set theSBounds to {{572, 64}, {332, 515}} set position of window "Google ...
rubik's sphere's user avatar
4 votes
5 answers
3k views

Shortcut to eject all external hard drives but not MobileBackups

So far I've been using the following AppleScript to eject all external drives at once conveniently using a shortcut: tell application "Finder" eject (every disk) end tell This script is ...
gentmatt's user avatar
  • 49.3k
3 votes
1 answer
2k views

Can't save AppleScript file when created by touch

I'm used to create file using touch before opening them with open. But I came to this following problem : When I do this with AppleScript files AppleScript Editor is able to open the file but unable ...
Matthieu Riegler's user avatar
3 votes
3 answers
2k views

Trigger 'Gather Windows' programmatically (or other quick way)

I'm trying to make myself a little script that I can run on the fly that gathers all my open windows onto the main display. I think a good starting place would be to be able to trigger Gather Windows ...
Nathan Greenstein's user avatar
3 votes
3 answers
1k views

How to create a blank RTF file in AppleScript?

I want to be able to create a new TextEdit document with an AppleScript file. The AppleScript file will then be triggered by a system-wide keyboard shortcut via FastScripts. Specifically, I want the ...
rubik's sphere's user avatar
2 votes
1 answer
9k views

How to make applescript hold a key for 2 seconds

So I am trying to make a script that moves me forward and backward to prevent afk in a game but the game is not registering the key as it is too short here is what I have so far. repeat 100 times ...
corneredphoton's user avatar
2 votes
1 answer
1k views

Find specific attached disk, not volume, by Applescript

I have a script I use to format any inserted SD card, copy data from specific folders to it, then eject. Each format/copy is triggered manually, as part of a batch process involving maybe a hundred ...
Tetsujin's user avatar
  • 114k
2 votes
2 answers
5k views

How do I trigger a script when a second monitor is attached

I am on macOS El Captain (upgrading to High Sierra soon) and I'm looking for a tool which can trigger an AppleScript or shell script every time when the number of monitors/displays attached to the ...
halloleo's user avatar
  • 1,295
2 votes
1 answer
586 views

Applescript/Javascript to click submenu item of Jupiter Notebook in Safari

When I run a.ipynb jupyter notebook file in Safari, it opens at local host http://localhost:8888/notebooks/a.ipynb#. NOTE: The script should work for any *.ipynb file, a.ipynb is just an example. ...
BhishanPoudel's user avatar
1 vote
2 answers
1k views

AppleScript Error - Can’t get group 1 of window "Control Center"

Expected Run an AppleScript in order to toggle the Mac's Bluetooth on/off. Actual Error The action “Run AppleScript” encountered an error: “System Events got an error: Can’t get group 1 of window &...
AdamHurwitz's user avatar
1 vote
1 answer
837 views

How to launch an Application with a keyboard shortcut?

Using only built-in functionality, how can I launch an Application such as Terminal by key command?
negNaN's user avatar
  • 13

1
2 3 4 5
10