0

I've been playing around with various UNIX commands and came across this one to display a dialog:

osascript -e 'tell app "System Events" to display dialog "Hello World"'

I'd like to change the position of the dialog. For most commands, I can just use man command to figure out how to do something for that command. However, man osascript doesn't tell me how I can change the position of the dialog box. How can I modify the command to put the dialog in a different place?

animuson
  • 53,861
  • 28
  • 137
  • 147
MacBoss123541
  • 198
  • 1
  • 17
  • `man osascript` points you to [AppleScript](http://www.apple.com/applescript) for details on AppleScript itself. The chances are that you can extend the command to include positional information. Having given you that URL, when you chase it, you end up at Automator... – Jonathan Leffler Jul 06 '13 at 04:24
  • If you're a registered developer, there are definitely manuals on Automator and AppleScript available (mostly dated 2007). I'm not sure whether they're publicly available, though. – Jonathan Leffler Jul 06 '13 at 04:30
  • @animuson: If I may ask, why is [tag:positioning] not appropriate on this question? The tag wiki excerpt says “Positioning often refers to the process of placing viewable elements.” This question clearly relates to positioning a user interface element on a screen. – icktoofay Jul 06 '13 at 06:23
  • @icktoofay: I'm in the process of cleaning it out due to ambiguity. 85% of the questions tagged with [tag:positioning] refer to CSS positioning, which now has its own tag: [tag:css-positioning]. Unfortunately before merging, that requires me to retag the other 15%. If you know of a better, more specific tag than [tag:positioning], feel free to add it. – animuson Jul 06 '13 at 06:28
  • How about. ui-positioning – markhunte Jul 06 '13 at 08:39

2 Answers2

3

First, to get help with applescript just open the AppleScript Editor application and look under the help menu. The applescript language guide is in there and other tools. Also under the file menu is "Open Dictionary" which will show you the specific commands for applications.

To see the information about display dialog, open the dictionary of StandardAdditions and use the search field to find the command.

To answer your question, no, you cannot specify the location of a "display dialog" window. There are no parameters in that command for positioning the window, as you'll see in the dictionary. In addition, no other commands will help you either because you can't issue other commands while the dialog window is open because the code pauses while the window is open waiting for a response from the dialog window (like when you press the OK button).

If you need to set the position of a window to display information to a user then you'll need to use some other dialog tool other than "display dialog". You could create your own window in cocoa or google for some alternatives like cocoaDialog, SKProgressBar, and Notification Center.

regulus6633
  • 18,848
  • 5
  • 41
  • 49
1

There is a round-about way to go about this, which may be useful in some scenarios. Try the following:

on displayMessage(msg)
tell application "Finder"
   activate
   set c to (count windows)
   ignoring application responses
       display dialog msg with icon note
   end ignoring
end tell

tell application "System Events"
   tell application process "Finder"
       repeat until ((count windows) > c)
           delay 0.2
       end repeat
       set position of window 1 to {0, 22}
   end tell
end tell
end displayMessage

displayMessage("I'm over here!")

Credit for this little script goes to a post here.

In implimenting this myself, I found it was limited to whether or not the application that is being called (Finder, in the example) supports the count window command (or whether it has API support at all).

I realise I've dragged up a question from 2013. I am posting this answer here in case it is of use to the OP or, more likely, someone else with a similar question.

inspirednz
  • 4,807
  • 3
  • 22
  • 30
  • I ran this on my (OS X 10.10) Mac and all it did was activate Finder and then freeze Script Editor (presumably from the `ignoring application responses`?). Oh, well. – Resigned June 2023 Sep 29 '15 at 01:49