Friday, August 14, 2020

#1 2016-02-04 05:41:07 am

hsp
Member
Registered: 2012-07-14
Posts: 29

Create an encrypted DMG of a folder

Hello,

I am not at all confortable with scripts and command line and I would like to create an encrypted DMG of a folder.
I am able to do it with the script below, however I am not able to encrypt I get always the following error:
--> error "hdiutil: create failed - Appel ioctl incompatible avec le périphérique"
Also, I would like to not specify a size, but have the size of the folder content and also to be able to add files later (-format UDRW).

Help would be appreciated.

Thanks and regards
Henri

Applescript:

set sourceFolder to POSIX path of (choose folder with prompt "choose source folder")
set sourceFolderName to name of (info for sourceFolder)
set destinationFolder to POSIX path of (choose folder with prompt "choose destination folder")
set sourceFolder2 to POSIX path of sourceFolder


set dmgFileNamePath to (sourceFolderName & ".dmg")
set myNewPath to destinationFolder & dmgFileNamePath
try
   do shell script "hdiutil create -encryption AES-128 -size 500m -format UDRW -nospotlight -srcfolder " & sourceFolder2 & " -volname " & quoted form of sourceFolderName & " " & myNewPath
end try

Offline

 

#2 2016-02-04 11:43:53 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 958

Re: Create an encrypted DMG of a folder

Hi. I don't see a "nospotlight" option in the hdiutil man page.
This works for me:

Applescript:


set isTarget to (choose folder) as text
do shell script "hdiutil create -encryption -format UDRW -srcfolder" & space & ((isTarget)'s POSIX path's quoted form) & space & (isTarget's text 1 thru -2 & ".dmg")'s POSIX path's quoted form

Last edited by Marc Anthony (2016-02-04 11:55:16 am)

Offline

 

#3 2016-02-04 03:06:09 pm

hsp
Member
Registered: 2012-07-14
Posts: 29

Re: Create an encrypted DMG of a folder

Hi Marc,

Thank you for the reply, I still get an error (see the response window result below):

tell application "Script Editor"
    choose folder
        --> alias "Macintosh HD:Users:hsp:Documents:sidenote:"
end tell
tell current application
    do shell script "hdiutil create -encryption -format UDRW -srcfolder '/Users/hsp/Documents/sidenote/' '/Users/hsp/Documents/sidenote.dmg'"
        --> error "hdiutil: create failed - Appel ioctl incompatible avec le périphérique" number 1
Résultat :
error "hdiutil: create failed - Appel ioctl incompatible avec le périphérique" number 1

Concerning the -nospotlight, when you type into the terminal the following:
hdiutil create -help

you can see this:

Image from Folder options:
       -srcfolder <source folder>
       -[no]spotlight        do (not) create a Spotlightâ„¢ index

Thanks and regards
Henri

Offline

 

#4 2016-02-04 03:37:05 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 958

Re: Create an encrypted DMG of a folder

An ioctl, or input/output control, has something to do with the kernel; the error that its "incompatible with the peripheral" is not particularly helpful, and, unfortunately, is too arcane for me. Perhaps it will help others to help you, if you post your OS version. I tested my code in OS 10.9.5.

Offline

 

#5 2016-02-04 04:22:52 pm

hsp
Member
Registered: 2012-07-14
Posts: 29

Re: Create an encrypted DMG of a folder

Hi Marc and thanks for your help.

I am under 10.11.3

Regards
Henri

Offline

 

#6 2018-01-15 12:31:59 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 958

Re: Create an encrypted DMG of a folder

I don't know if the OP is still looking for an answer at this point, however, after installing Sierra and revisiting this question, the error appears related to a permissions issue.


Applescript:

set sourceFolder to (choose folder with prompt "select a folder to store") as text
set destination to (choose folder with prompt "define an end point") as text
set fileVar to "nom" --the dmg's filename


#iConcerning volname, not specifying same results in volname = sourceFolder
do shell script "printf 'whatever password' | hdiutil create -srcfolder " & sourceFolder's POSIX path's quoted form & " -encryption -stdinpass -fs HFS+" & space & (destination & fileVar)'s POSIX path's quoted form

--if volname desired
--set volumeVar to "expanded" --the mounted dmg's name
--do shell script "printf 'whatever password' | hdiutil create -srcfolder " & sourceFolder's POSIX path's quoted form & " -encryption -stdinpass -fs HFS+ -volname " & volumeVar's quoted form & space & (destination & fileVar)'s POSIX path's quoted form

Last edited by Marc Anthony (2018-01-15 12:38:03 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)