Could anybody explain how to prevent the “Your Script is not allowed assistive access” error window when running a compiled script?
Below, at the very bottom of this post, is a script from a recent discussion. If I compile it using osacompile
, like
osacompile -o list-view.app list-view.applescript
then its name under System Settings > Privacy & Security > Accessibility is simply applet, which is not very descriptive and convenient, of course. But at least, if I turn it on, the script works, and the error window doesn’t appear.
Okay, but because I really don’t like my applet to be called just applet, I searched the internet for how it can be changed to something meaningful. I tried to edit Info.plist
using
plutil -replace CFBundleName -string "New Applet Name" "/path/to/applet.app/Contents/Info.plist"
but this didn’t help. Another solution that is often suggested is to open the script in Script Editor and export it as application manually: File > Export > File Format = Application. And yes, it worked!
When I opened System Settings > Privacy & Security > Accessibility, my applet was named the same as the file itself, list-view, which is fine.
But!.. For some reason, at least for me (macOS 15.3.2), turning it on, contrary of as we turned on applet, doesn’t prevent the “Your Script is not allowed assistive access” window to appear!
I tried to run the script after removing list-view from there (that is: 1. remove list-view from the System Settings > Privacy & Security > Accessibility list → 2. run the script, so that list-view will appear there again, turned off → 3. turn it on), but this didn’t help, the error window still appears.
Do you have the same problem? Yes, no? Please don’t ignore this part, thanks! And how it can be fixed or maybe there is a workaround which I’m not aware of?
In its current state it seems that scripts that are exported from Script Editor as applications are broken in some way?
Okay, and now the script itself:
global mediumDelay
global shortDelay
global longDelay
set mediumDelay to 1 -- edit as necessary
set shortDelay to 0.5 -- edit as necessary
set longDelay to 2 -- edit as necessary
tell application "Finder"
set targetFolder to target of front Finder window
try
set theSubfolders to every folder of the entire contents of targetFolder
if class of theSubfolders is not list then set theSubfolders to theSubfolders as list
on error
set theSubfolders to {}
end try
end tell
set theFolders to (targetFolder as list) & theSubfolders
-- optionally
set theSubfoldersMaxNumber to 10 -- edit as desired
if (count theSubfolders) is greater than theSubfoldersMaxNumber then
display dialog "This script will only reset" & space & theSubfoldersMaxNumber & space & "or fewer subfolders" buttons {"OK"} cancel button 1 default button 1
end if
repeat with aFolder in theFolders
tell application "Finder" to set the target of Finder window 1 to aFolder
resetFinderWindow()
delay mediumDelay -- edit as necessary
end repeat
tell application "Finder"
set target of front Finder window to container of targetFolder -- previous...
set target of front Finder window to targetFolder -- ...and back
end tell
on resetFinderWindow()
tell application "Finder"
tell front Finder window
set current view to list view
end tell
activate
delay mediumDelay -- edit as necessary
tell application "System Events" to tell process "Finder"
tell menu item "Show View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
delay mediumDelay -- edit as necessary
repeat with boxName in {"Comments", "Date Added", "Date Created", "Date Last Opened", "Date Modified", "Kind", "Size", "Tags", "Version"}
if boxName is in {"Date Modified", "Kind", "Size"} then -- edit as desired
tell checkbox boxName of group 1 of window 1 to if value is 0 then click
else
tell checkbox boxName of group 1 of window 1 to if value is 1 then click
end if
end repeat
delay mediumDelay -- edit as necessary
tell menu item "Hide View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
end tell
tell front Finder window
set options to its list view options
end tell
tell options -- edit as desired
--set properties to {calculates folder sizes:false, shows icon preview:false, icon size:small, text size:14, sort column:name column, uses relative dates:true} -- optionally
set properties of column name column to {index:1, sort direction:normal, width:100}
set properties of column comment column to {index:2, sort direction:normal, width:1}
set properties of column creation date column to {index:3, sort direction:normal, width:1}
set properties of column kind column to {index:4, sort direction:normal, width:1}
set properties of column label column to {index:5, sort direction:normal, width:1}
set properties of column modification date column to {index:6, sort direction:normal, width:1}
set properties of column size column to {index:7, sort direction:normal, width:1}
set properties of column version column to {index:8, sort direction:normal, width:1}
end tell
end tell
end resetFinderWindow