Friday, May 29, 2020

#1 2020-03-21 11:00:49 am

Blizzard
Member
From:: OWL/Germany
Registered: 2020-03-21
Posts: 4

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

Offline

 

#2 2020-03-21 09:25:25 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

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

Applescript:


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.

Last edited by KniazidisR (2020-03-21 09:54:19 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-03-22 09:54:59 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 481

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

Blizzard wrote:

The folder has been created, but i am not sure how to handle that Errormessage in Scriptdebugger. Maybe i can ignore it?



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.

Applescript:

set folderPath to "SSD500_Cache_20181202:" as alias

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

Last edited by peavine (2020-03-25 04:52:23 pm)


2018 Mac mini - macOS Catalina

Offline

 

#4 2020-03-22 11:45:58 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

peavine wrote:

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.

Applescript:

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:

Applescript:


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":

Applescript:


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

Last edited by KniazidisR (2020-03-23 12:31:42 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2020-03-23 01:17:47 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

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.

Last edited by KniazidisR (2020-03-23 01:45:42 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#6 2020-03-23 10:32:32 am

Blizzard
Member
From:: OWL/Germany
Registered: 2020-03-21
Posts: 4

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

KniazidisR wrote:

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

Applescript:


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.



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)

Applescript:

--
--    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

Last edited by Blizzard (2020-03-23 10:37:10 am)

Offline

 

#7 2020-03-24 03:09:40 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

Blizzar wrote:

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)


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

Applescript:


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:

Applescript:


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

Or, you can do this:

Applescript:


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:

Applescript:


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

Whole code (2 variants):

Applescript:


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

Applescript:


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

Last edited by KniazidisR (2020-03-24 01:23:12 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#8 2020-03-24 07:41:29 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 481

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

KniazidisR wrote:

You should add the specifier folder in the tell application "Finder" block, because [at location] of make command expects folder and not its Posix path. So, need the coercion, like this:

Applescript:


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

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



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

Last edited by peavine (2020-03-24 09:43:51 am)


2018 Mac mini - macOS Catalina

Offline

 

#9 2020-03-24 09:56:05 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4370

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

peavine wrote:


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:

Applescript:

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

Offline

 

#10 2020-03-24 01:27:55 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

peavine wrote:

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


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


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#11 2020-03-24 03:12:38 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4370

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

@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

Offline

 

#12 2020-03-24 03:45:15 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

Yvan Koenig wrote:

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


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.

Last edited by KniazidisR (2020-03-24 03:57:02 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#13 2020-03-26 12:58:03 pm

Blizzard
Member
From:: OWL/Germany
Registered: 2020-03-21
Posts: 4

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

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

Offline

 

#14 2020-03-26 03:43:48 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4370

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

Something like that would do the job.

Applescript:

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

Last edited by Yvan Koenig (2020-03-26 03:44:24 pm)

Offline

 

#15 2020-03-29 06:37:56 am

Blizzard
Member
From:: OWL/Germany
Registered: 2020-03-21
Posts: 4

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

Yvan Koenig wrote:

Something like that would do the job.

Applescript:


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



Hello Yvan,
thanks for your help... but ;-)
i ran into other Errors as i tried to recode it like you advised me...

Applescript:


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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)