I need to have a Mac Mail rule to display a pop up box whenever a new email comes in. I wrote a simple Applescript to display the popup box (just a Display Dialog line of code) and linked that script to the rule in Mail. Mail runs on my second (extension) monitor in a two-monitor setup. I need the pop up box to also appear on the second (extension) monitor, not on the main monitor.
How can I force the Display Dialog popup box to appear on this second monitor?
I thought of a way I might be able to get it to work… but don’t know how to code it. Is there a way to have the Display Dialog open the dialog box at a certain X / Y coordinate? If so, I can make that X / Y coordinate somewhere on the extended monitor. Would that work? How could I code that?
Thanks for the reply - I copied that script and added my display message but nothing happens when I run it. Here is my script (below). I am trying to have it display the message at the defined coordinates (currently set to 0,22 in the script). What am I doing wrong?
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
say "New Order on the iPad" using "Cellos"
end displayMessage
displayMessage("A New Online Order Has Arrived")
It appears that this script does not work in Lion. Is there another way to move a displayed Display Dialog box to a different X Y Coordinate or an extension monitor? What if didn’t use Display Dialog - is there something else I could use that would work? All I need to do is have a script that opens a message - it can even be a picture! - in an extension monitor (or at a particular X Y coordinate that will be on the extension monitor rather than the main monitor).
Is anyone else getting an error with the script but me? When I run the script, absolutely NOTHING happens at all. It just says “running” at the bottom of the Script Editor and never does ANYTHING. I’ve run it on 5 different Macs - same result. All running Lion.
I too have found that Nigel’s script appears to do nothing. I am running Leopard!
If you don’t mind using Preview, I have this:
try
tell application "Preview" to quit without saving
end try
do shell script "defaults write com.apple.Preview \"NSToolbar Configuration ImageToolbar3\" -dict-add \"TB Is Shown\" 0" -- Hides the toolbar
tell application "Preview" to activate
tell application "Preview" to open the file ((path to me) & "Contents:Resources:test.psd" as string) -- test.psd is saved in the "Contents:Resources:" folder of the application bundle!
tell application "Preview" to set bounds of every window to {660, 373, 1000, 685} -- change co-ordinates to suit
tell application "Preview" to set name of every window to "Pre-Robot"
delay 3 -- remove this delay to keep the window active!
tell application "Preview" to quit without saving
do shell script "defaults write com.apple.Preview \"NSToolbar Configuration ImageToolbar3\" -dict-add \"TB Is Shown\" 1" -- Sows the toolbar next time Preview is launched!
Save this script as an application bundle, then (right click its icon) show package contents and save your dialog image in the Contents:Resources: folder, (called test.pdf here - you can obviously call it what you want, but change the file name reference within this script).
This script also changes the ‘Preview.plist’, first hiding the toolbar (so as it looks more like a startup screen splash or dialog box), then again at the end of the script to turn the toolbar back on.
Hopefully you will be able to use something from this.
I have amended the previous script, replacing the delay with a repeat, basically waiting for the display to be closed before continuing and re-setting the Preview preferences.
try
tell application "Preview" to quit without saving
end try
do shell script "defaults write com.apple.Preview \"NSToolbar Configuration ImageToolbar3\" -dict-add \"TB Is Shown\" 0"
tell application "Preview" to activate
tell application "Preview" to open the file ((path to me) & "Contents:Resources:test.psd" as string)
tell application "Preview" to set bounds of every window to {660, 373, 1000, 685}
tell application "Preview" to set name of every window to "Pre-Robot"
set x to 1
repeat while x = 1
if window 1 of application "Preview" exists then
set x to x
else
set x to 0
end if
end repeat
tell application "Preview" to quit without saving
do shell script "defaults write com.apple.Preview \"NSToolbar Configuration ImageToolbar3\" -dict-add \"TB Is Shown\" 1"
Please bear in mind that my script is a bit of a hack and was intended as an amusing aside to Stefan’s correct assertion in the other thread that an AppleScript dialog can’t normally be repositioned. The idea uses an application unconnected with the script at that moment to display the dialog. The ‘ignoring application responses’ wrapper frees the script to move on and perform the GUI Scripting on the dialog window instead of waiting for the dialog to be dismissed and return a result. The “other application” obviously has to be right for the moment and the script can’t know the result of the dialog.
However, it should work as a demo in AppleScript Editor and apparently does on Budgie’s twin-monitor, Lion system. If “NOTHING happens at all” includes no dialog being displayed, then the second part of the script is probably stuck in an eternal loop waiting for the dialog window to appear. The question in this case is “Why no dialog?”
Do either of these not display a dialog at all?
tell application "Finder"
activate
display dialog "Hello!" with icon note
end tell
tell application "Finder"
activate
ignoring application responses
display dialog "Hello!" with icon note
end ignoring
end tell
In Snow Leopard, there’s some visual confusion if there’s a Finder window open in another “space” when the script’s run, but the dialog is displayed (albeit off-screen) and the script runs to completion. I’ve no experience of using two monitors with one computer, so I’ve no idea how that may affect things.
It doesn’t work on my Tiger system either. The dialog doesn’t display and the script just loops waiting for it. However, this works on both machines:
on displayMessage(msg)
tell application "Finder"
activate
set c to (count windows)
end tell
do shell script "osascript -e 'tell application \"Finder\" to display dialog \"" & msg & "\" with icon note' >/dev/null 2>&1 &"
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
say "New Order on the iPad" using "Cellos"
end displayMessage
displayMessage("A New Online Order Has Arrived")
You’ll have to be careful with the messages displayed. Some characters such as apostrophes and quotes will need escaping to go into the shell script string.