position of dialog box on screen

I would like my dialog box to appear in the upper left of the screen instead of the middle. What is the syntax for that? I couldn’t find any online.

Thanks



repeat -- start of shell
	
	--finds the end of the in-out array 
	tell application "Microsoft Excel"
		set inOutList to value of used range of active sheet
	end tell
	
	-- the loop that decrements array
	--"i" is a pointer to array
	
	repeat with i from (count inOutList) to 1 by -1
		set {startValue, stopValue} to item i of inOutList -- puts in-out values to variables
		set inValue to startValue * 1000.01528202278
		set outValue to stopValue * 1000.01528202278
		
		tell application "QuickTime Player 7"
			activate --allow QT to be run by script
			tell document 1 --the active file in QT
				set selection start to inValue
				set selection end to outValue --set in out points
				set current time to inValue --show in point
				delay 2 --wait show out point
				set current time to outValue
				
			end tell
			
			--branch point	
			--make display for dialog box	
			set messageText to "cut " & quote & name of document 1 & quote & return & ¬
				return & " start: " & inValue & ¬
				return & "end: " & outValue & ¬
				return & "Adjust before Cut" & ¬
				return & "Use only this Button for Cut"
			my displayMessage(messageText) --call subroutine displayMessage
			
			--(msg) sets buttons and response
			-- if default do tell-cut-end tell
			--if not skip next 3 lines go to next item in in-out list
			
			tell document 1
				cut
			end tell
		end tell
	end repeat
	--my displayMessage2("Next Show ?")
	
	
	
	---start of exit
	activate me
	set {button returned:buttonReturned} to display dialog "Project Complete " buttons {"Quit", "Next Project"}
	if buttonReturned is "Quit" then
		exit repeat
	end if
end repeat


--subroutine when called activate and pass processing power to QT
on displayMessage(msg)
	activate me
	display dialog msg buttons {"Cut"} default button 1
	activate application "QuickTime Player 7"
end displayMessage


on displayMessage2(msg)
	activate me
	display dialog msg --buttons {"Quit Script",} default button 1
	--activate application "QuickTime Player 7"
end displayMessage2


Hi,

the position of dialog boxes in plain AppleScript cannot be changed.
You can define custom dialog windows in Xcode with AppleScriptObjC

Not sensibly, anyway. :wink:

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!")

very nice :slight_smile:

Hi,

I’m sorry for open this post again, but I’m trying to do the same thing to a simple display dialog message with no luck, please help.

my displayMessage(display dialog "write what you want to be in the dialog box here")

on displayMessage(msg)
	tell application "Finder"
		activate
		set position of window 1 to {170, 36}
	end tell
end displayMessage

displayMessage

Thank you
Regards,
Marco

Model: Mac Pro 2013
AppleScript: 2.8.1
Browser: Safari 601.2.7
Operating System: Mac OS X (10.10)

Hi Marco. Welcome to MacScripter.

All of the original code you quoted is required to make the trick work.

There are two main difficulties in trying to position a script-generated dialog:

  1. There’s no provision for doing so.
  2. Once a ‘display dialog’ command has been sent, a script will normally wait for the dialog to be dismissed before continuing, so it can’t actually do anything with the dialog while it’s open.

The trick in my handler is that the script tells the Finder (a different application from the one running the script) to display the dialog, but without waiting for the Finder’s response. This means the Finder does the waiting and the script’s free to continue.

The Finder itself can’t be scripted to reposition the dialog because it’s waiting for the dialog to be dismissed. And in any case, a dialog window isn’t a scriptable item in the Finder. But the dialog here is a window belonging to the Finder. So the script tells System Events, which controls the GUI, to move the dialog as if the user had dragged it across the screen.

If my script doesn’t work on your machine, you may need to allow “assistive access” when the error message appears: https://support.apple.com/en-us/HT202802

Edit: Looking more closely at your script, you’re apparently new to AppleScript. If you want to be able to type text into a dialog, you need to specify a ‘default answer’, which will appear as an editable field in the dialog. If you don’t particularly have any default text you want to appear, just specify an empty text: “”.

on displayMessage(msg)
	tell application "Finder"
		activate
		set c to (count windows)
		ignoring application responses
			display dialog msg default answer ""
		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 {170, 36}
		end tell
	end tell
end displayMessage

displayMessage("write what you want to be in the dialog box here")

The problem now, of course, since we’re ignoring the dialog response, is that there’s no way to return the entered text to the script! You’ll have to forget about positioning the dialog if you need that response. Sorry.

Hi Nigel,

First I want to thank you for your time to answer me.

Yes I’m a new enthusiast of Applescripting, I’ve manage with the help of a great guy (Oliver), that point me out the direction of some nice reading and how to use Ui Browser to help me out with a no applescript Applications to do some work and gave me some nice tips.

And I manage to do a workflow to a thing that I need to do 190 times. The video is doing everything with applescript excepting the click OK on the dialog box

https://www.youtube.com/watch?v=hmHW_WCjrfI

But I have other scripts that use more dialog box and even with the delay time, they appear on top of something I need to do before going to the next step of the script, it’s quite annoying. That’s why I find this post and try to understand if this could be useful to my script.

I’m using set position and cliclick https://www.bluem.net/en/mac/cliclick/ app in conjunction of Applescript to be faster and more precise.

It worked like a charm, thank you so much.

I didn’t put the default answer in the dialog box because I don’t need it for what I’m trying to do, I just need that dialog box explain some notes of what to do with the session before continue to another part of the script.

-- this is a short example what I'm looking for

tell application "System Events"
	tell process "Pro Tools"
		click menu item "I/O..." of menu 1 of menu bar item "Setup" of menu bar 1
		tell window "I/O Setup"
			keystroke 3 using {command down}
			click radio button "Bus 3 of 6"
			key code 36
		end tell
	end tell
end tell

tell me to activate
display dialog "please clean the session before proceed" -- I'm looking to move this dialog box to another place but only pass to the next part of the script when I hit OK

tell application "System Events"
	tell process "Pro Tools"
		click radio button "Bus 3 of 6"
		click button of UI element 3 of row 1 of table 1
		keystroke "VO_MIX"
	end tell
end tell

I manage to do this but it’s the same “problem” :frowning:

on cliClick(coordinate)
	do shell script "/opt/local/bin/cliclick " & " -r " & coordinate -- cliclick is a great little app
end cliClick

on displayMessage(msg)
	tell application "Finder"
		activate
		set c to (count windows)
		ignoring application responses
			display dialog msg -- I remove the default answer because I don't need it for this time
		end ignoring
	end tell
	
	tell application "System Events"
		tell application process "Finder"
			repeat until ((count windows) > c)
				delay 0.2
			end repeat
			tell window 1
				set {xPosition, yPosition} to position
				set {xSize, ySize} to size
				do shell script "/opt/local/bin/cliclick dd:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2) - (45) & " du:160,30"
			end tell
		end tell
	end tell
end displayMessage

displayMessage("please clean the session before proceed")

I wish that notifications could do the same thing as dialog boxes.

Thank you so much Nigel I just learn that is impossible to to, maybe using AppleScriptObjC? :slight_smile: I need to check it out.

Cheers.
Marco

nice, I need to add 2 buttons, “END”, “Continue”…is this possible

FYI, if you don’t mind using a Library, Shane’s Dialog Toolkit Plus allows you to position dialogs and windows.