activate display dialog

this handler is for extracting zip file.
The problem is that when “The Unarchiver.app” extracts the files, it takes focus away from the dialog box. The dialog box does not remain active.
The Unarchiver.app does not launch. It only extracts. There is nothing in the Activity Monitor that I could use ( i mean wait for some process to end…)
I want to solve this problem without switching from “The Unarchiver.app” to some other application for extracting files.

on open thefiles
	repeat with thefile in thefiles
		try
			set thename to name of (info for thefile)
			tell application "System Events" to open thefile
			tell application "System Events" to activate
                      --tell me to activate
			set displaydialog to display dialog "Do you want to delete the file " & thename & " after extracing?" buttons {"Yes", "No", "Cancel"} default button "Yes"
			if button returned of displaydialog is "Yes" then tell application "System Events" to delete thefile
		on error e
			tell me to activate
			display dialog e
		end try
	end repeat
end open

This might be what you want. To be honest I not sure of the point of this scritp??

on open thefiles
	tell application "Archive Utility"
		activate
		repeat with thefile in thefiles
			
			try
				set theName to name of (info for thefile)
				
				open thefile
				
				
				delay 1
				set displaydialog to display dialog "Do you want to delete the file " & theName & " after extracing?" buttons {"Yes", "No", "Cancel"} default button "Yes"
				
			on error e
				
				display dialog e
			end try
		end repeat
		quit
		if button returned of displaydialog is "Yes" then tell application "System Events" to delete thefile
	end tell
	
end open

?

This may not be perfect, but at least the dialog box does appear, where before the app icon just bounced in the dock.

on open thefiles
	repeat with thefile in thefiles
		try
			set thename to name of (info for thefile)
			tell application "System Events" to open thefile
			--tell application "System Events"
			--activate
			--end tell
			--tell me to activate
		end try
		
		delay 2
		tell me to display dialog "Do you want to delete the file " & thename & " after extracing?" buttons {"Yes", "No", "Cancel"} default button "Yes"
		if button returned of result is "Yes" then
			try
				tell application "System Events"
					activate
					delete thefile
				end tell
			on error e
				tell me to activate
				display dialog e
			end try
		end if
	end repeat
end open

Greg Ledger
macproductionartist.wordpress.com

Hi,
Thanks for the replies. I have not tested the scripts yet.

Valid question!! :slight_smile:

I frequently download zip files. Sometimes, I want to delete the the last downloaded zip file after extracting. Sometimes I may want a display dialog to ask for a password when I know that the file I am extracting requires a password. Sometimes, I may not want to delete them after extracting. The script that I posted is only to get started towards writing the complete script which can do all the three things based on my choice. Does it make any sense now? Would you like to suggest any alternatives/alternative ways? Ideally i would like to use 7za (http://www.7-zip.org/) but if fails to extract archives on my system. I don’t know of any other open-source command line utility.

Hmm…
For a start you could use the Defaults to get the “Archive Utility” app to take care of deleting.
Which maybe Safer, as it will not delete it until it is fully extracted (i.e a very Large zip file)
Like this script does. You will need to add a final check if “Archive Utility” is still running or doing anything
and add the final quit.

on open thefiles
	tell application "System Events"
		set sourcePath to ((path to preferences folder of user domain) & "com.apple.archiveutility.plist" as Unicode text) as alias
		set the dearchive_move_after to (property list item "dearchive-move-after" of contents of property list file (POSIX path of sourcePath))
		set the Old_dearchive_move_after to value of dearchive_move_after
		
	end tell
	repeat with thefile in thefiles
		set theName to name of (info for thefile)
		set processName to ""
		
		set displaydialog to display dialog "Do you want to delete the file " & theName & " after extracing?" buttons {"Yes", "No", "Cancel"} default button "Yes"
		if button returned of displaydialog is "Yes" then
			set counter to 0
			repeat until processName is not ""
				log processName
				set counter to counter + 1
				if counter ≤ 30 then
					
					try
						tell application "System Events" to set processName to unix id of process "Archive Utility"
						
						do shell script "kill " & processName
						delay 1
						tell application "System Events" to set processName to unix id of process "Archive Utility"
						
					on error
						set processName to "notRunning"
						tell application "System Events"
							set the value of dearchive_move_after to "/dev/null"
							tell application "Archive Utility" to open thefile
						end tell
					end try
				else
					exit repeat
				end if
			end repeat
		end if
	end repeat
	tell application "System Events" to set the value of dearchive_move_after to Old_dearchive_move_after
end open

Also it maybe better to look at using a Hotkey app like ‘Spark’ to run you script. Rather than drag and drop you can run on selection.

i get the error "can’t get property list item “dearchive-move-after”
I also tried changing

set sourcePath to ((path to preferences folder of user domain) & "com.apple.archiveutility.plist" as Unicode text) as alias

to

"Leopard:Users:cris2:Library:Preferences:com.apple.archiveutility.plist" as alias

I opened the plist and I did not see any such property. I am working harder on finding some command-line utility so that scripting becomes easier.

The fact that i use “on open” does not mean that I intend to use it as a droplet. Quicksilver and Launchbar require script to begin with “on open” so that they can be run on the selected files in those applications.

Ah, Just realised that if you have never change any of the prefs in the Archive Utility app
Then they will not be there.

You can open the prefs and change the After expanding selection to something else.
Close the Prefs. And to Make sure off a write out Quit it.

You then should have the pref.

Or you can write in the full key set in the script.

Here is the new code,

on open thefiles
	tell application "System Events"
		set sourcePath to ((path to preferences folder of user domain) & "com.apple.archiveutility.plist" as Unicode text) as alias
		set the this_plistfile to property list file (POSIX path of sourcePath)
		if not (exists (property list item "dearchive-move-after" of this_plistfile)) then
			make new property list item at end of property list items of contents of this_plistfile with properties {kind:string, name:"dearchive-move-after", value:"."}
		end if
		set the dearchive_move_after to (property list item "dearchive-move-after" of contents of this_plistfile)
		set the Old_dearchive_move_after to value of dearchive_move_after
		
	end tell
	repeat with thefile in thefiles
		set theName to name of (info for thefile)
		set processName to ""
		
		set displaydialog to display dialog "Do you want to delete the file " & theName & " after extracing?" buttons {"Yes", "No", "Cancel"} default button "Yes"
		if button returned of displaydialog is "Yes" then
			set counter to 0
			repeat until processName is not ""
				log processName
				set counter to counter + 1
				if counter ≤ 30 then
					
					try
						tell application "System Events" to set processName to unix id of process "Archive Utility"
						
						do shell script "kill " & processName
						delay 1
						tell application "System Events" to set processName to unix id of process "Archive Utility"
						
					on error
						set processName to "notRunning"
						tell application "System Events"
							set the value of dearchive_move_after to "/dev/null"
							tell application "Archive Utility" to open thefile
						end tell
					end try
				else
					exit repeat
				end if
			end repeat
		end if
	end repeat
	tell application "System Events" to set the value of dearchive_move_after to Old_dearchive_move_after
end open

Hi,
Thanks for the quick reply, Mark. I will see how it goes. I am in the middle of another script now. :slight_smile: