I want to execute the bash ‘find’ command over an external hard drive.
In Terminal, this works perfectly.
In AppleScript, this results in an error.
do shell script "find /Volumes/HD/"
The error returns one or more ‘Permission denied’ messages such as these :
I tried to work around this by writing the ‘find’ command in a file and call it through the ‘source’ command, but the result is the same.
I would appreciate it if someone could help me solve this issue. Thanks in advance. W.
Browser: Safari 605.1.15
Operating System: macOS 10.14
For search queries anywhere outside your home folder you need elevated privileges since these locations are owned by root. In this case you must supply your admin password provided that you’re an administrator.
do shell script "find system_location" with administrator privileges password YOUR_PASSWORD
In both cases you avoid the password prompt. In the latter form, you hand over the handling of the secure information to the shell.
If you don’t care if find looks in the permission-denied areas, a possible workaround is to ignore these areas. For example, on my computer, the first command in the following returned the error shown, while the second worked OK.
do shell script "find " & quoted form of "/Volumes/Backup 1"
--> error "find: /Volumes/Backup 1/.Trashes: Permission denied
--> find: /Volumes/Backup 1/.DocumentRevisions-V100: Permission denied
--> find: /Volumes/Backup 1/.TemporaryItems: Permission denied" number 1
do shell script "find " & quoted form of "/Volumes/Backup 1" & "; true"
--> returns files as expected