Why does my AppleScript code run in Script Editor but not as an exported application?
I wrote an AppleScript code that runs without issue in Script Editor, but when I export it as an application and try to run it, I receive the error message "<app name> is not allowed assistive access. system Events got an error: <app name> is not allowed assistive access. (-25211)". I have already added Script Editor and my application to the accessibility settings, but the problem persists. I have also tried reopening the settings and restarting my computer, but the issue remains. What else can I do to fix this problem? Thank you!
And here is the code:
on run
set theURL to "http://www.poe.com"
set targetWindowTitles to {"Sage - Poe", "GPT-4 - Poe"}
set targetWindowName to ""
set noActiveWindows to true
tell application "System Events"
-- Check if Safari is running
set isRunning to (count of (every process whose name is "Safari")) > 0
if isRunning then
set safariApp to first application process whose name is "Safari"
set safariWindows to windows of safariApp
if (count of safariWindows) > 0 then
set noActiveWindows to false
repeat with win in safariWindows
set winName to name of win
if winName is in targetWindowTitles then
set targetWindowName to winName
exit repeat
end if
end repeat
end if
end if
end tell
tell application "Safari"
if not isRunning or noActiveWindows or targetWindowName is "" then
if not isRunning then
-- Launch Safari but don't activate to prevent opening a blank window
launch
end if
-- Create a new document and navigate to theURL
make new document with properties {URL:theURL}
set bounds of front window to {0, 22, 800, 822}
-- Close all other blank windows
close (every window whose name is "Untitled" and index is not 1)
-- Make the new window the frontmost window
activate
set index of front window to 1
else if targetWindowName is not "" then
activate
set targetWindow to first window whose name is targetWindowName
set index of targetWindow to 1
end if
end tell
end run