Need a script to quickly create ISO files from folders. It works. But for some reason, checking the file for existence does not work correctly. What am I doing wrong?
-- get current path
try
tell application "Finder" to set the this_folder to (folder of the front window) as alias
tell application "Finder"
-- Get selected items
set selected_items to the selection
repeat with x in selected_items
set ISO_path to POSIX path of this_folder
set ISO_full_name to ISO_path & name of x & ".iso"
if exists POSIX file ISO_full_name as alias then
display dialog "The file already exists" buttons {"Cancel", "Delete"}
delete POSIX file ISO_full_name as alias
-- Create iso image
do shell script "hdiutil makehybrid -iso -joliet -o" & space & quoted form of ISO_full_name & space & quoted form of ISO_path
display notification ISO_full_name with title " " subtitle "The image was created successfully"
end if
end repeat
end tell
--on error
--display alert "No file selected"
end try
How can I make the script process only folders and cdr files?
As far as I understand, to add support for the cdr extension only, need to add a property
V.Yakob. The line of your script that begins with “if exists” has two issues. First, it should not contain “as alias”, and, second, POSIX file is best not used in a Finder tell statement. Also, do shell script should probably be in a handler. I modified your script below and it works in my testing.
BTW, I believe there is an error in the hdiutil command line, which causes it to create an image of the entire parent folder, which I assume is not what you want. Anyways, you might want to have a look at that.
tell application "Finder"
set selected_items to selection as alias list
if (count selected_items) = 0 then display dialog "No folders selected" buttons "OK" cancel button 1
set ISO_path to (folder of the front window) as text
repeat with x in selected_items
set ISO_full_name to ISO_path & name of x & ".iso"
if exists file ISO_full_name then
display dialog "The file already exists" buttons {"Cancel", "Delete"} cancel button 1
delete file ISO_full_name
end if
createISO(ISO_path, ISO_full_name) of me
end repeat
end tell
on createISO(ISO_path, ISO_full_name)
set ISO_path to POSIX path of ISO_path
set ISO_full_name to POSIX path of ISO_full_name
do shell script "hdiutil makehybrid -iso -joliet -o" & space & quoted form of ISO_full_name & space & quoted form of ISO_path
display notification ISO_full_name with title " " subtitle "The image was created successfully"
end createISO
Thanx :), I didn’t see the error. Changed, now the correct argument is being passed.
I fixed it, now it works great.
tell application "Finder"
set selected_items to selection as alias list
if (count selected_items) = 0 then display dialog "No folders selected" buttons "OK" cancel button 1
set this_folder to (folder of the front window) as text
repeat with x in selected_items
set ISO_path to this_folder & name of x
set ISO_full_name to ISO_path & ".iso"
if exists file ISO_full_name then
display dialog "The file already exists" buttons {"Cancel", "Delete"} cancel button 1
delete file ISO_full_name
end if
createISO(ISO_path, ISO_full_name) of me
end repeat
end tell
on createISO(ISO_path, ISO_full_name)
set ISO_path to POSIX path of ISO_path
set ISO_full_name to POSIX path of ISO_full_name
do shell script "hdiutil makehybrid -iso -joliet -o" & space & quoted form of ISO_full_name & space & quoted form of ISO_path
display notification ISO_full_name with title " " subtitle "The image was created successfully"
end createISO
Is there any possibility to process only folders or cdr files with a script? So that, for example, if I accidentally selected a jpg file along with the folder(s), it would simply be ignored.
You can filter out selected items that are not folders and that do not have a CDR file extension as shown below. I am not familiar with CDR files and the following assumes they are regular files with a CDR extension. If that’s not the case, the test in the if statement would need to be changed.
I tested the following with your new script with two folders and two text files selected in a Finder window and it worked as expected (it ignored the two text files).
tell application "Finder"
set theSelection to selection
set selected_items to {}
repeat with anItem in theSelection
if class of anItem is folder or name extension of anItem is "cdr" then set end of selected_items to anItem as alias
end repeat
-- rest of script
end tell
peavine, If you create an image using the Disk Utility, you can select the image format “master CD/DVD”, an image with the cdr extension will be created.
With your help, it turned out! Thanx
The final version
tell application "Finder"
set the_selection to selection
set selected_items to {}
repeat with Filtered_Item in the_selection
if class of Filtered_Item is folder or name extension of Filtered_Item is "cdr" then set end of selected_items to Filtered_Item as alias
end repeat
set selected_items to selected_items as alias list
if (count selected_items) = 0 then display alert "No folder(s) or cdr file(s) selected" buttons "OK" as critical
set this_folder to (folder of the front window) as text
repeat with Item_to_convert in selected_items
set ISO_path to this_folder & name of Item_to_convert
set ISO_full_name to ISO_path & ".iso"
if exists file ISO_full_name then
display dialog "The file already exists" buttons {"Cancel", "Delete"} cancel button 1
delete file ISO_full_name
end if
createISO(ISO_path, ISO_full_name) of me
end repeat
end tell
on createISO(ISO_path, ISO_full_name)
set ISO_path to POSIX path of ISO_path
set ISO_full_name to POSIX path of ISO_full_name
try
do shell script "hdiutil makehybrid -iso -joliet -o" & space & quoted form of ISO_full_name & space & quoted form of ISO_path
on error number 1
display alert "hdiutil error: attach of disk image failed" as critical
do shell script "rm -f" & space & ISO_full_name
end try
display notification ISO_full_name with title " " subtitle "The image was created successfully"
end createISO