How to fix: Error: a privilege violation occurred (errAEPrivilegeError

Hey to all…

First of all… i am a newbie to Applescript…

I want to create a folder in a script, but got the Error below…
do shell script “mkdir -p ‘/Volumes/SSD500_Cache_20181202/tempDT3/’”

Error: a privilege violation occurred (errAEPrivilegeError:-10004)

The folder has been created, but i am not sure how to handle that Errormessage in Scriptdebugger.

Maybe i can ignore it?

It just makes me nervous to see an error message and just leave it like that? Only how do I get the message fixed?

I would be very pleased about a feedback from you.

Best
Rolf

The error occurs because for creating folder at certain Mac directories (as root directory, in your example) the system requires administrator privileges:


set directoryString to quoted form of "/Volumes/SSD500_Cache_20181202/tempDT3/"

do shell script "mkdir -p " & directoryString with administrator privileges

Apple (and we too) would not want everyone to delve into this important directories. The same error should occur, if you attempt to create the folder at some directory, which has setting read/only from owner of the directory.

It’s curious that the error is reported yet the folder is created. I ran the script (with different path but on an external drive) in Script Editor and it worked fine with no error message. I don’t have Script Debugger and can’t test that.

You may want to try creating the folder with the following script (verify path) to see what happens. Also, you may want to make note of your macOS version, which can make a difference.

set folderPath to "SSD500_Cache_20181202:" as alias

tell application "Finder"
	make new folder at folderPath with properties {name:"tempDT3"}
end tell

Peavine,

I tried your script on Mojave 10.14.4
Both with Script Editor and Script Debugger it asks for the password (that is, administrator privileges), when “SSD500_Cache_20181202:” is the name of the hard disk. It seems, the OP has hard disk, so the system requires administrator privileges to make changes in the root directory of hard disk. I have not USB disk now to try your script. But I believe, with external disks it should work as you sad.

The following script doesn’t ask the password, because I create my custom temp folder where it should be created normally. That is, not at root directory, but at tmp folder of root directory:


do shell script "mkdir -p '/tmp/tempDT3/'"

Now, other example, assuming that the OP want to create folder “SSD500_Cache_20181202” at tmp folder of root directory, and in the created folder the OP want to create other folder, named “tempDT3”:


do shell script "mkdir -p '/tmp/SSD500_Cache_20181202/tempDT3/'"

Blizzard,

Can you provide little more information about your code? For example, larger fragment of your script.

It seems to me your error errAEPrivilegeError is relied to other reason. Most likely, to Standard Additions command do shell script. which shouldn’t be into tell some application block…

Because running only your given code line on root directory I get other error: permission denied…
Lack of information does not help to understand your problem, and therefore to find its solution.

Hej KniazidisR,
Thanks for your feedback…

Yeah, you’re right… I overlooked the fact that I wanted to create the new directory tempDT3 as a subdirectory in Temp. I forgot to specify the “temp”.
So the new directory “tempDT3” should be in the directory: “/Volumes/SSD500_Cache_20181202/temp/”.
The disk is a attached USB3.0 Device and its name is SSD500_Cache_20181202

My goal is to create the directory “tempDT3” in the directory “Volumes/SSD500_Cache_20181202/temp/” if it does not already exist.
If it exists, then nothing should be done.

So i corrected my code to:

    set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"
    
    tell application "Finder"
        make new folder at folderPath with properties {name:"tempDT3"}
    end tell

and get this error in Scriptdebugger:

make new folder at “/Volumes/SSD500_Cache_20181202/temp/” with properties {name:“tempDT3”}
Error: the Apple Event handler failed (errAEEventFailed:-10000)

--
--	Created by: RL
--	Created on: 23.03.20
--
--	Copyright © 2020 RL, All Rights Reserved
--

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	try
		
		
		
		set myPath1 to "/Volumes/HDD2000_20160523/02_DEVONthink/DT3_DT_DB_BRA/DT-DB_BRA.dtBase2"
		
		
		set myBackupPath to "/Volumes/DatenBRA/Daten_BRA/SystemDaten_RL/Devonthink_DatenbankenBackups/"
		set myTempPath to "/Volumes/SSD500_Cache_20181202/temp/tempDT3/"
		set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"
		
		
		
		tell application "Finder"
			make new folder at folderPath with properties {name:"tempDT3"}
		end tell
		
		
		
		do shell script "mkdir -p " & quoted form of myTempPath
		
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "Fehler" message error_message as warning
	end try
	
	
end tell

Model: iMac
AppleScript: AppleScript version “2.4” – Yosemite (10.10) or later
Browser: Firefox 74.0
Operating System: macOS 10.14

You should add the file specifier in the tell application “Finder” block. So, need the coercion, like this:


set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"

tell application "Finder"
	make new folder at Posix file folderPath with properties {name:"tempDT3"}
end tell

NOTE: In your big snippet you shouldn’t tell to application “Finder” second time (this way you create same nested tell, which is wrong). Doesn’t exist application “Finder” of application “Finder”, right? So, use only this:


make new folder at Posix file folderPath with properties {name:"tempDT3"}

Or, you can do this:


do shell script "mkdir -p '/Volumes/SSD500_Cache_20181202/temp/tempDT3/'"

NOTE: If with this variant you still get violation error, then try insted this:


tell current application to do shell script "mkdir -p '/Volumes/SSD500_Cache_20181202/temp/tempDT3/'"

Whole code (2 variants):


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set myPath1 to "/Volumes/HDD2000_20160523/02_DEVONthink/DT3_DT_DB_BRA/DT-DB_BRA.dtBase2"
set myBackupPath to "/Volumes/DatenBRA/Daten_BRA/SystemDaten_RL/Devonthink_DatenbankenBackups/"
set myTempPath to "/Volumes/SSD500_Cache_20181202/temp/tempDT3/"
set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"

tell application "Finder"
	try
		make new folder at Posix file folderPath with properties {name:"tempDT3"}
	on error error_message number error_number
		if the error_number is not -128 then display alert "Fehler" message error_message as warning
	end try
end tell

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set myPath1 to "/Volumes/HDD2000_20160523/02_DEVONthink/DT3_DT_DB_BRA/DT-DB_BRA.dtBase2"
set myBackupPath to "/Volumes/DatenBRA/Daten_BRA/SystemDaten_RL/Devonthink_DatenbankenBackups/"
set myTempPath to "/Volumes/SSD500_Cache_20181202/temp/tempDT3/"
set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"

set resultCode to (do shell script "mkdir -p " & quoted form of myTempPath)
if resultCode ≠ 0 then display alert "Fehler" message error_message as warning

KniazidisR. Don’t you have to use the HFS path or POSIX file for the above to work.

You are perfectly right.

It would be:

set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"
set folderPath to POSIX file folderPath
tell application "Finder"
	make new folder at folderPath with properties {name:"tempDT3"}
end tell

It’s funny because Finder may create a subfolder in a folder defined as a POSIX file but if it’s asked to execute:
exists folderPath
it respond false.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 24 mars 2020 16:55:22

Yes, it was my mistake. Now my scripts is corrected.

@KniazidisR

Isn’t it playing with matches to use POSIX file which belongs to the OSAX “Standard Additions” inside a tell application block ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 24 mars 2020 22:12:09

Finder is smart enough to not be a problem for it. With a third-party application this can be a violation error problem. But as you have noticed, it is always better to have the commands of the Standard Additions outside the tell block of the application. Just in case.

However, this topic has already bothered me, since I have already lost interest in it. Let the OP fix it if he wants. Actually, I didn’t want to use Finder, since, in my opinion, it is better to use mkdir here. Because it don’t need try block and is faster. Finder solution (correct) suggested by Peavine.

Hej to all you guys…

Thank you very much for the detailed explanations.
Very helpful for me…

Your solutions now work fine for me, but only until the script tries to create the directory, if it already exists. Then the script immediately jumps to error handling.

i thought it would be easy to check if the directory exists or not and depending on what the check returns, the directory will be created or the command will be skipped.

But how… I have searched and read a lot on the Internet, but have not found a solution that is feasible for me

I thought Applescript as a function like
If Not folderexist then
make new folder at…
EndIf

But it looks like it was thought too easy. Can someone please help me again with the best way to do this?

I would be very pleased about a feedback from you.

Have a lovely day ahead!
Best regards,

Rolf

Something like that would do the job.

set folderPath to "/Volumes/SSD500_Cache_20181202/temp/"
set folderPath to POSIX file folderPath
tell application "Finder"
	set newName to "tempDT3"
	if not (exists folder ((folderPath as text) & newName)) then
		make new folder at folderPath with properties {name:newName}
	end if
end tell

For my own use, as I hate the Finder and dislike Shell, I would do that with ASObjC which may create a deep arborescence in a single call.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 26 mars 2020 22:42:54

Hello Yvan,
thanks for your help… but :wink:
i ran into other Errors as i tried to recode it like you advised me…


set myCacheFolderPath to "/Volumes/SSD500_Cache_20181202/temp/"
set myCacheFolderName to "DTbackupTempDT3"

tell application "Finder"
	try

--Rolfs Backup Pfade 
set myBackupPath to "/Volumes/DMS/02_DevonThink/02_Devonthink_DatenbankenBackups/" -- AblageOrt der Backups

set myTempPath to myCacheFolderPath & myCacheFolderName & "/"
set myCacheFolderPath to POSIX file myCacheFolderPath
        --Rolf Backup Pfad ENDE
        
-- Prüfung und ggf. Erstellen des CacheFolders
        
if not (exists folder ((myCacheFolderPath as text) & myCacheFolderName)) then
            make new folder at myCacheFolderPath with properties {name:myCacheFolderName}
        end if




but…
as i showed it here i got the error: (in Scriptdebugger)

get POSIX file “/Volumes/SSD500_Cache_20181202/temp/”
Error: no such object (e.g. specifier asked for the 3rd, but there are only 2) (errAENoSuchObject:-1728)

“„Finder“ hat einen Fehler erhalten: „POSIX file "/Volumes/SSD500_Cache_20181202/temp/"“ kann nicht gelesen werden.”

Can you see whats wrong?

I would be very pleased about a feedback from you.

Greeetings
Rolf