Getting error 1728 when trying to run this script

Am trying to figure out why the following AppleScript program fails - get an error when it finds a matching notificationcenter dialog with the name of “Disk Not Ejected Properly” and tries to simulate clicking the Close button. That is when i get the 1728 error. Am rather a newbie so am sure I’m doing something wrong, but not able to see what the problem is, so welcome any ideas/suggestions. Thanks…

use AppleScript version “2.4” – Yosemite (10.10) or later
use scripting additions

tell application “System Events”
tell process “NotificationCenter”
set numwins to (count windows)
repeat with i from 1 to numwins by 1
tell window i
set rawElements to UI elements
if name of item 1 of result = “Disk Not Ejected Properly” then
click button “Close” of window i
end if
end tell
end repeat
end tell
end tell

Here is the image of the 1728 error dialog when run from ScriptDebugger program:

The issue is the click button command is already in a window i tell block, and you’re script is confusing things by specifying window i again.

Replace that line with:

click button "Close"

Also, here’s a tip for the forum: When you’re quoting a script precede it with three ` characters (to the left of 1 on most keyboards) and the word AppleScript

and at the end of your script do three ` characters again.

``` applescript
–your applescript here
```

That way you get nicely formatted script that can be easily opened in a script editor:

tell application "System Events"
	tell process "NotificationCenter"
		set numwins to (count windows)
		repeat with i from 1 to numwins by 1
			tell window i
				set rawElements to UI elements
				if name of item 1 of result = "Disk Not Ejected Properly" then
					click button "Close"
				end if
			end tell
		end repeat
	end tell
end tell

Great – thanks so much. Really appreciate the tip and the help!!!

Am gonna give the new version 8 of Script Debugger a try as soon as I have a Mojave (or newer) system to give it a try on.

Script Debugger has been around a long time and look forward to many more years of having fun with it and learning new stuff. Thanks for all the work you guys do to support AppleScript!!!

-bob

1 Like

There is a logic error in my program - was closing the NotificationCenter windows in window order (from first to last) but need to do it in reverse window order (from last to first), as got an error about a nonexistent window. Hope this makes sense – here is the new program in case anyone is interested (with the triple quote tip from Ed):

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- 2022-11-10 - Version 1.0 - modified slightly from original source code
-- 2022-11-11 - Version 1.3 - need to close in reverse order as get an error otherwise

tell application "System Events"
	tell process "NotificationCenter"
		set numwins to (count windows)
		-- have to do in reverse order because
		--    window numbers change dynamically
		--    as they are deleted if done in
		--    in normal order.
		repeat with i from numwins to 1 by -1
			tell window i
				set rawElements to UI elements result
				if name of item 1 of result = "Disk Not Ejected Properly" then
					click button "Close"
				end if
			end tell
		end repeat
	end tell
end tell

One other question I have - is there a way to set the “version” of an AppleScript program without manually editing the Info.plist file located in the xxx.app/Contents/Resources folder, ie directly in the AppleScript code itself??? By this I mean when you click on the “About” menu item when the program is running and up pops a dialog box that says what the program is and what version and other similar info?

Thanks again for the help…

-bob