1

I run the following code in Terminal:

osascript "/Users/Me/Desktop/Run this script on wake.scpt"

If the first dialog of my .scpt file is a choose from list dialog, then this dialog will be unselected. That is, I cannot simply hit the enter key to press "OK"; I must first click anywhere on the dialog to make the top bar of the dialog change from white to grey, and only then can I hit enter to proceed.

To be clear, the dialog comes to the front just fine - it is simply not selected.

However, if the first dialog is a display dialog or display alert dialog, then the dialog is automatically selected. It just so happens that the initial dialog of my .scpt file is a choose from list dialog.

I tried writing activate me on the line above the choose from list dialog, but this did not do anything.

When I run the "Run this script on wake.scpt" from within Script Editor, the choose from list dialog is in fact selected. Hence, we know that the issue is related to osascript.

Does anyone have a workaround to force the choose from list dialog to be automatically selected?

I've tried implementing a default selection by inserting the default items parameter in the choose from list command (even though I don't actually want a default item to exist in this case). I thought that doing this might force the dialog to be selected. But, still, the list dialog is unselected.

As a last resort, I suppose that I could use AppleScript to mouse-click the center of the screen (where the dialog is located). But, I'd prefer a more elegant solution, as AppleScript can be unreliable when it comes to mouse clicks.


If you are wondering why I am employing osascript in the first place, it is because I am using SleepWatcher to automatically run an AppleScript when my computer wakes from sleep. (Here is a very helpful guide that I used to set up SleepWatcher.)

This is the full text of my .wakeup file:

#!/bin/bash
osascript "/Users/Me/Desktop/Run this script on wake.scpt"
  • As I wrote in my answer below (unnoticed by the OP) your (his) problem is not AppleScript but the fact that osascript is not a mere command but a process of its own. Therefore you (he) must activate application "Terminal" NOT "me" (= osascript) … – clemsam lang Dec 4 '18 at 18:42
1

This is weird.. For now, I'd recommend that you save your script as an executable. This can be done by opening your Applescript in the Script Editor, then clicking the File menu, then Export, then choosing "Application" in the File Format dropdown box. You could then create an Applescript that executes this application.

  • Unfortunately, this solution does not solve the issue. I saved my AppleScript as an .app file via Automator. I then tried launching the .app via Terminal using the two different methods explained here. I also tried simply double-clicking the app & launching it from Finder the standard way. I also tried launching the app with AppleScript in a separate .scpt file, as you suggested. In all of these cases, the initial choose from list dialog is unselected. But, now we know that the bug is broader than osascript. – rubik's sphere Mar 8 '17 at 15:09
  • Please disregard my previous comment. I have found that, as long as I include activate me on the line above choose from list, then when running the .app version of the AppleScript file, the initial list dialog is necessarily selected, no matter how the .app file is run. Thanks! – rubik's sphere Mar 8 '17 at 16:09
  • No problem! Glad that using .app worked! – Jake3231 Mar 8 '17 at 20:04
0

As I already found out in context of a different question, your problem is the "me" in your script and therefore is not only "related" to osascript:

osascript IS YOUR problem…

… as osascript is NOT a mere command in Terminal but actually a process of its own.
If you want to open a file from Terminal you have to "activate Terminal" and NOT "activate me" [= osascript].

(Since you already accepted one answer as your "chosen" one, I will confine my answer to this hint.)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.