Running Scripts in Package Maker

How can I get Package Maker to automatically put the Script Menu icon in the user’s Finder Menu Bar? I figured out how to make a Package Maker installer that will install a script I wrote in the user’s Library/Scripts folder. The only problem is that the user would then have to open up the Script Editor app, go to the Script Editor preferences and click on “Show Script menu in menu bar” before he/she would be able to access the script from the Finder Menu bar. I’d prefer to make it easier than that for the user. The below AppleScript successfully adds the Script Menu icon to the Finder Menu Bar, but I can’t get it to work in the Package Maker installation. (I tried adding it as a postinstall script in Package Maker).

Any ideas how I could get something like this to work automatically as part of the installation process so the user isn’t burdened with extra steps?

--Bringing up the preferences dialog
tell current application
	my do_submenu("Script Editor", "Script Editor", "Preferences…")
end tell

--Clicking the show script menu in menu bar
tell application "System Events"
	tell process "Script Editor"
		set myUI to every UI element
		set theCheckbox to checkbox "Show Script menu in menu bar" of window 1
		tell theCheckbox
			if not (its value as boolean) then click theCheckbox
		end tell
	end tell
end tell

--------------------------------------------------------------------------------------------------------------
--------------------------------------- NEEDED FUNCTIONS  -------------------------------------------
--------------------------------------------------------------------------------------------------------------

--The UI Scripting select submenu function
on do_submenu(app_name, menu_name, menu_item)
	try
		-- bring the target application to the front
		tell application app_name
			activate
		end tell
		tell application "System Events"
			tell process app_name
				tell menu bar 1
					pick menu bar item menu_name
					tell menu bar item menu_name
						tell menu menu_name
							pick menu item menu_item
							click menu item menu_item
							(*tell menu item menu_item
								tell menu menu_item
									pick menu item submenu_item
									click menu item submenu_item
								end tell
							end tell*)
						end tell
					end tell
				end tell
			end tell
		end tell
		return true
	on error error_message
		return false
	end try
end do_submenu

Browser: Safari 604.3.5
Operating System: Mac OS X (10.13 Developer Beta 3)

Your script to add the script menu relies on Script Editor being open and the front application. Just to be sure, are you opening it and making it the front app (and preferably closing it later)?


--Bringing up the preferences dialog

tell application "Script Editor"
	activate -- added
	my do_submenu("Script Editor", "Script Editor", "Preferences…")
end tell

--Clicking the show script menu in menu bar
tell application "System Events"
	tell process "Script Editor"
		set myUI to every UI element
		tell window 1
			set theCheckbox to checkbox "Show Script menu in menu bar"
			tell theCheckbox
				if not (its value as boolean) then click theCheckbox
			end tell
			tell (the first button whose description is "close button")
				click it
			end tell
		end tell
	end tell
end tell

tell application "Script Editor" to quit

--------------------------------------------------------------------------------------------------------------
--------------------------------------- NEEDED FUNCTIONS  -------------------------------------------
--------------------------------------------------------------------------------------------------------------

--The UI Scripting select submenu function
on do_submenu(app_name, menu_name, menu_item)
	try
		-- bring the target application to the front
		tell application app_name
			activate
		end tell
		tell application "System Events"
			tell process app_name
				tell menu bar 1
					pick menu bar item menu_name
					tell menu bar item menu_name
						tell menu menu_name
							pick menu item menu_item
							click menu item menu_item
							(*tell menu item menu_item
								tell menu menu_item
									pick menu item submenu_item
									click menu item submenu_item
								end tell
							end tell*)
						end tell
					end tell
				end tell
			end tell
		end tell
		return true
	on error error_message
		return false
	end try
end do_submenu