Monday, March 1, 2021

#1 2021-02-19 02:56:46 am

Registered: 2012-03-02
Posts: 28

Bash command 'find' does not work through AppleScript

I want to execute the bash 'find' command over an external hard drive.

In Terminal, this works perfectly.

find /Volumes/HD/

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 :

find: /Volumes/HD/.DocumentRevisions-V100: Permission denied
find: /Volumes/HD/.TemporaryItems: Permission denied
find: /Volumes/HD/.Trashes: Permission denied

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.

AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

Filed under: find, bash



#2 2021-02-19 07:17:57 am

Registered: 2015-08-04
Posts: 87

Re: Bash command 'find' does not work through AppleScript

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


do shell script "echo YOUR_PASSWORD | sudo -S find system_location"

In both cases you avoid the password prompt. In the latter form, you hand over the handling of the secure information to the shell.

Last edited by scrutinizer82 (2021-02-19 07:18:35 am)

Scripting in Mac OS X 10.7.5, OS X 10.9.5, macOS 10.14.6



#3 2021-02-19 07:50:08 am

From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 790

Re: Bash command 'find' does not work through AppleScript

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

2018 Mac mini - macOS Catalina



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)