Questions tagged [applescript]

AppleScript is an end user scripting language that has been available in Mac computers since System 7 Pro (7.1.1). It allows for automation of system tasks, communication between processes, and creation of workflows, amongst other functions.

AppleScript is a inter-application scripting language, designed to control and exchange data between scriptable applications. Users can use AppleScript to combine the functionality of multiple scriptable Mac applications to form a new application to meet their special need or demand without "reinventing the wheel".

Resources

8740 questions
21
votes
5 answers

"Sort Lines in Selection" for Xcode 4

I like Textmate's "Sort Lines in Selection" feature a lot. Is there something similar for Xcode 4? If not, what would be the best way to integrate such a feature (a plugin, Applescript, ...)?
Lars Schneider
  • 5,530
  • 4
  • 33
  • 58
21
votes
2 answers

concatenate a string and a variable into a string in applescript

I have to write an Applescript to automount a folder depending on the user. Applescript Editor throws this error. A end of line can’t go after this identifier. Here the portion of the script that is throwing the error. try set short_name to…
jeremyjjbrown
  • 7,772
  • 5
  • 43
  • 55
21
votes
2 answers

osascript using bash variable with a space

I am using osascript in Bash to display a message in Notification Center (Mac OS X) via Apple Script. I am trying to pass a text variable from Bash to the script. For a variable without spaces, this works just fine, but not for one with…
Bernd
  • 675
  • 3
  • 13
  • 23
21
votes
2 answers

How can I copy text to the clipboard using AppleScript

I would like to create an application using AppleScript to copy the system info and email it to myself. I know to to do the emailing aspect and how to make the email have the content of whatever is in the clipboard. How might I use AppleScript…
ThatCrazyCow
  • 469
  • 2
  • 5
  • 17
21
votes
1 answer

Applescript: on clicking Menu Bar item via gui script

I'm trying to make an applescript for an application called F.lux that clicks the menu item "Disable for an Hour" as indicated in the screenshot below: The element path is indicated in the screenshot below: Here is my code thus far: tell…
Black Milk
  • 515
  • 2
  • 8
  • 17
20
votes
4 answers

AppleScript: on error (try) line number

Is it possible to get the line number, where the script threw an error? Example: try set a to "abc" + "123" on error line number num display dialog "Error on line number " & num end try
Tyilo
  • 28,998
  • 40
  • 113
  • 198
20
votes
5 answers

is there a way to eject all external hard drives from the command line? (OS X)

Is there a way to eject all the mounted hard drive volumes on an OS X computer from the command line? Applescript is OK if I can wrap that in a shell script.
dan
  • 43,914
  • 47
  • 153
  • 254
19
votes
2 answers

How can I programmatically add a space to mission control?

I want to create a new space (and also be able to delete it later), without having to go through the standard misson control gui. Is there any way to do this programmatically? Either via terminal commands, applescript or some cocoa?
Dag Stuan
  • 191
  • 1
  • 4
19
votes
2 answers

How to start new conversation in iMessage using AppleScript?

So I'm working on creating an applescript which essentially automates sending an imessage. What I have working now is: on run {msg, phoneNum} tell application "Messages" set serviceID to id of 1st service whose service type = iMessage …
kvel
  • 497
  • 1
  • 4
  • 12
19
votes
4 answers

run applescript on 2x-click

OK, this feels like an idiot question, but I'm stuck - I don't know the first thing about AppleScript. I have a .scpt file and I want to double-click it and just have it run, but instead every time I click, it opens up the AppleScript Editor. This…
scottru
  • 5,280
  • 3
  • 21
  • 13
19
votes
3 answers

How to activate Mac OS X application with a given process ID?

I know the process id of an application in Mac OS X. How can I switch to it (using applescript, or python, or whatever)? By "switch", I mean, put in focus. The usual solution is to use the applescript code tell application "Foo" activate, but here…
Olivier Verdier
  • 46,998
  • 29
  • 98
  • 90
19
votes
6 answers

Determine OS X keyboard layout ("input source") in the terminal/a script?

I would like to determine the OS X keyboard layout (or "input source" as OS X calls it) from the terminal so that I can show it in places like the tmux status bar. So I want to know if the current layout is "U.S." or "Swedish - Pro" for…
Henrik N
  • 15,786
  • 5
  • 82
  • 131
19
votes
5 answers

Play a sound when AppleScript is done

I have no idea how to use AppleScript, how I got my little bash script working in the first place was beyond me. I'm currently using an AppleScript to run my bash script and it works fantastically. It is below. do shell script…
user3261383
  • 193
  • 1
  • 1
  • 4
19
votes
3 answers

Applescript - Bring window to foreground

I have an application with several windows opened at the same time. I'd like to bring a specific window to foreground (I know its title). At the moment I'm using a combination of keys to achieve this task but I'd like to try something different…
Giorgio
  • 1,603
  • 5
  • 29
  • 52
19
votes
4 answers

Applescript: Open a Folder in Finder

I m trying to open a folder in Finder using AppleScript. The following is my code. I want the folder WorkSpace to open in Finder, but it opens the Parent Folder /Volumes/MyMacDrive/Mani and highlights the WorkSpace folder. I want the contents of…
Manikandaraj Srinivasan
  • 3,557
  • 5
  • 35
  • 62