Skip to content

Instantly share code, notes, and snippets.

@loshlee
Created January 14, 2025 20:27
Show Gist options
  • Save loshlee/30329f0d7f2ab151efed53365db6ccae to your computer and use it in GitHub Desktop.
Save loshlee/30329f0d7f2ab151efed53365db6ccae to your computer and use it in GitHub Desktop.
Add or remove executability for macOS AppleScript Droplet source (multiple items allowed)
on open the_items
my execabilify(the_items)
end open
on execabilify(fl)
repeat with i in fl
try
do shell script "chmod " & "755" & space & quoted form of POSIX path of i with administrator privileges
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
end try
end repeat
end execabilify
on run
set the_items to ((choose file with multiple selections allowed) as list)
my execabilify(the_items)
end run
on open the_items
my execabilify(the_items)
end open
on execabilify(fl)
repeat with i in fl
try
do shell script "chmod " & "644" & space & quoted form of POSIX path of i with administrator privileges
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
end try
end repeat
end execabilify
on run
set the_items to ((choose file with multiple selections allowed) as list)
my execabilify(the_items)
end run
@loshlee
Copy link
Author

loshlee commented Jan 14, 2025

Create droplet application(s) by saving these AppleScripts as applications using Script Editor. If file(s) are dropped, you'll be prompted to enter your administrator password, and the file(s) will be altered so that the executability permission is added or removed (depending on which AppleScript is used). Making the file(s) executable changes permissions for each (using the chmod command) to 755, and making the file(s) "un-executable" changes permissions for each (using the chmod command) to 644.

If you run the AppleScripts (by double-clicking the application file or by opening in Script Editor and choosing "Run", you will be presented with an "Open" dialog, in which you can make multiple target selections by holding the shift key for adjacent files in the window, or by holding the command key for nonadjacent files. In either case, you will be prompted to enter your administrator password to apply the change.

These are powerful commands, so please understand precisely what you are doing before using these AppleScripts.

Because of the inherent danger of using these AppleScripts, I haven't provided for cases in which the target pathnames contain spaces. You may modify the scripts if you need them to handle such cases, or you can move or rename the targets on your system if needed before using the AppleScripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment