EzDevInfo.com

applescript interview questions

Top applescript frequently asked interview questions

Can the UI Automation instrument be run from the command line?

Is there a way to open the UIAutomation instrument through the terminal?

Will it be possible to write an AppleScript to open Apple's UIAutomation tool and load the application to be tested?

Can you please tell me is there any way through scripting or through the command line we can open UIAutomation and select the app to be tested, as well as select the test script?


Source: (StackOverflow)

How to add launch parameter to Google Chrome on Mac? [closed]

I wanna run Chrome on Mac with the parameter --enable-speech-input.

Can anyone tell me the steps to do this and the steps to undo this? (If one day I wanna run Chrome without the launch parameter)


Source: (StackOverflow)

Advertisements

Open URL in new Safari tab with AppleScript

Is it possible to use AppleScript to open a link in a new tab in Safari?


Source: (StackOverflow)

How do I make a Mac Terminal pop-up/alert? Applescript?

I want to be able to have my program display an alert, notice, whatever that displays my custom text. How is this done? Also, is it possible to make one with several buttons that sets a variable?

Similar to batch's: echo msgbox""<a.vbs&a.vbs


Source: (StackOverflow)

Restrict 'Open Quickly's scope to currently open project in Xcode?

CMD+Shift+O ( ⌘⇧O ) brings up the 'Open Quickly' feature of Xcode. Much like CMD+T in Textmate & Sublime Text 2. Its scope of search seems to include system headers outside of my project.

Is there a way to restrict this scope to the currently open project? I can't find anything in Xcode preferences. This feature would be much more useful if this were possible.

Open Quickly


Source: (StackOverflow)

Applescript equivalent of "continue"?

I have a simple 'repeat with' in an AppleScript, and would like to move on to the next item in the "repeat" conditionally. Basically I'm looking for something similar to "continue" (or break?) in other languages.

I'm not well versed in AppleScript but I have found it useful a few times now.


Source: (StackOverflow)

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

I need to invoke a keyboard shortcut from within an AppleScript code, e.g. Cmd+Ctrl+Opt+E.


Source: (StackOverflow)

Open an .html file with default browser using Bash on Mac

So, this is what I need :

Let's say I have an index.html file.

How do I tell the terminal to open it using the default browser?

(Using AppleScript, BASH,...?)


Source: (StackOverflow)

Launch OSX Finder window with specific files selected

I'm trying to programmatically launch an OSX Finder window from an Xcode project. I need the window to open to a specific folder and have specific files within that folder automatically selected.

Does anyone know how to do this in either objective c, applescript, or Finder command-line parameters?

Thanks!


Source: (StackOverflow)

AppleScript Editor record doesn't work

I have opened the AppleScript Editor and pressed Record button.

Then I run TextEdit, create a file and put some text there.

When I click the Stop button in AppleScript Editor, nothing was recorded, the window is blank.

What is the problem?


Source: (StackOverflow)

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 the name is not useful because I have many instances of the same application running. I am however able to get the process id of the application.

How can I switch to this application programmatically?


Source: (StackOverflow)

Avoiding AppleScript through Ruby: rb-appscript or rubyosa?

Hello fellow Mac rubyists and AppleScript haters,

For those of you that have experience with both rubyosa and rb-appscript, I'd like the hear the pros and cons of each, which one you decided to stick with, and which one you'd recommend for a totally non-AppleScript savvy ruby old-timer. Also, are there any other options that I have missed?

As an aside, any tips dealing with the AppleScript side of the equation (e.g. browsing dictionaries, etc.) are also welcome.

Seeing some sample code also helps a lot.


Source: (StackOverflow)

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?


Source: (StackOverflow)

Import AppleScript methods in another AppleScript?

Is there a way to use defined AppleScript methods in other AppleScripts which reference the original AppleScript with something similar to import (f.e. in PHP)?

I wrote a methode to set Skype status and mood-text:

on setSkypeStatus(status, mood_text)
    tell application "System Events"
        set skypeRunning to count (every process whose name is "Skype")

        if skypeRunning > 0 then --only set status if skype is running
            tell application "Skype"
                set myStatus to "SET USERSTATUS " & status
                set myMood to "SET PROFILE MOOD_TEXT " & mood_text

                send command myStatus script name "AppleScript"
                send command myMood script name "AppleScript"
                return skypeRunning
            end tell
        else
            return skypeRunning
        end if
    end tell
end setSkypeStatus

now I'm searching for something like import skype_methods.scpt. Is there such a functionality. I can't something related with Google.


Source: (StackOverflow)

How to check in AppleScript if an app is running, without launching it - via osascript utility

Consider the following AppleScript:

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

set safRunning to is_running("Safari")
if safRunning then
    tell application "Safari"
      -- Stuff I only want executed if Safari is running goes here.
    end tell
    return "Running"
else
    return "Not running"
end if

The problem: when I run this via the osascript command line utility, if Safari is not running, it gets launched and the script reports "Running". This is not the behaviour I desire or would expect. Note that it works as desired/expected when run within AppleScript Editor.

Is this an osascript bug / known issue? Or is it somehow intended behaviour for reasons I'm missing? Can anyone get it to work as desired? (BTW I'm running OSX 10.7.5; I can't see how to get osascript to report a version number).

If you comment out the tell / end tell lines, it behaves as I'd expect: if Safari is not running, it doesn't launch it, and prints "Not running". So it seems to me like the tell is what's causing Safari to be launched, but it doesn't need to be actually executed, just present in the script...? For a while I wondered if maybe this was just how tell is supposed to work, but since it doesn't work like this in AppleScript Editor, I guess not...

In fact, here's another, madder, version with similar behaviour:

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

set safRunning to is_running("Safari")
return safRunning
if false then
    tell application "Safari"
    end tell
end if

This still always launches Safari, even though tell is inside an if false block after the return statement! (But again, this is fine in AppleScript Editor.)

BTW, this behaviour isn't limited to Safari, but it also isn't universal:

  • Affected apps include: Safari, TextEdit, iPhoto, AppleScript Editor, iTerm, ...
  • Non-affected apps include: Google Chrome, iTunes, Preview, Mail, Terminal, Address Book, Echofon, ...

So, does anyone have any ideas about how I might fix or route around this? Is it an osascript bug? Or am I missing something about AppleScript's semantics?

For context: I'm trying to write a script (to be embedded/called from some python) which queries open browsers for the URLs of any tabs they have open; I've got it all working fine except that it always launches Safari, whether it's open or not. I've boiled down that undesirable behaviour to the simple test case shown above. I'm not aware of any way to run this script from python without using osascript, other than appscript, which I don't want to use because it's no longer developed/supported/recommended.

Many thanks for all inputs / insights!


Source: (StackOverflow)