You can still remove annoying agreement prompts from Mac disk images (.dmg files)

I got tired of accepting agreement notices when opening distributed disk image (.dmg) files, so I created this script. It should work until certain people decide it shouldn’t. Create a MacOS Service using Automator with one Run AppleScript action, and make the service accept documents in Finder. Paste the following AppleScript into the Run AppleScript action and save. Here’s the shortest complete documentation I could find (written by Ben Waldie, an extremely proficient Mac automation enthusiast) that explains how to use Automator to quickly deploy AppleScripts as MacOS Services.

After you’ve added the MacOS Service, when you encounter a disk image that you’ve downloaded that wants you to agree to something before it opens, just click “disagree”, then launch the service from the contextual menu (right-click the disk image). After a few seconds (depending on the size of the image), you can double-click it and it will open with no further nagging.

------
property temppath : "/private/tmp/"

on run {input}

 (* Your script goes here *)
 repeat with the_item in input
 build_archive(the_item)
 end repeat
end run

on build_archive(the_item)
 --repeat with the_item in the_items
 set the_item to the_item as alias
 try
 tell application "Finder"
 set sost to ((container of file (the_item as string)) as alias) as string
 end tell
 set sost to POSIX path of sost
 on error therrr
 log therrr
 display dialog therrr
 set sost to "/Volumes/"
 end try
 set this_filepath to (the_item as string)

 if last character of this_filepath is ":" then
 tell me to set it_is_a_folder to true
 else
 set it_is_a_folder to false
 end if
 if not it_is_a_folder then
 set thesourcename to (name of (info for the_item))
 set the_source_file to POSIX path of this_filepath
 set pos_filepath to sost
 --set thesourcename to replace_chars(thesourcename, " ", "_")
 set dest_file to (quoted form of (temppath & thesourcename))
 set tempname to ((characters 1 thru -5 of thesourcename) & "temp")
 try
 set my_command to "hdiutil convert -format UDRW" & space & (quoted form of the_source_file) & space & "-o" & space & (quoted form of (temppath & tempname))
 do shell script my_command
 set my_2nd_command to "hdiutil convert" & space & (quoted form of (temppath & tempname & ".dmg")) & space & "-format UDZO -imagekey zlib-level=9 -o" & space & (quoted form of (temppath & thesourcename))
 do shell script my_2nd_command
 do shell script "rm" & space & (quoted form of (temppath & tempname & ".dmg"))
 on error onerr
 activate
 display dialog onerr
 end try

 if pos_filepath is "/Volumes/" then
 set pos_filepath to (POSIX path of (path to desktop folder))
 end if
 set targdetect to (pos_filepath & thesourcename)
 set name_target to alias (POSIX file targdetect)
 --use this instead of above to prevent overwriting your original disk image: set finishname to "_recomp"
 set finishname to ""
 set thesourcename to (((characters 1 thru -5 of thesourcename) & finishname) as Unicode text)
 tell me to do shell script "ditto -rsrcFork" & space & dest_file & space & "\"" & (pos_filepath & thesourcename) & ".dmg" & "\""
 end if
 try
 do shell script "rm" & space & dest_file
 end try
 --end repeat
end build_archive
------
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s