Hi, I’m working on a widget that involves some applescript. One of this widget’s functions is to decompress some .zip files and then process them. I need to have the widget wait for the files to finish decompressing, obviously, before processing them. Since I don’t know of any CLI ways to check that I decided to incorporate it into my decompressing applescript. Heres the code I use to decompress the files:
tell application "Finder" to open ((every file in ((the_Directory as POSIX file) as alias)) whose name extension contains "ZIP") using (("/System/Library/CoreServices/BOMArchiveHelper.app" as POSIX file) as alias)
This code works great. Here is what I am trying to use to delay the end of the script till decompression is done:
set isRunning to true
repeat while isRunning is true
set isRunning to false
tell application "System Events" to set procList to name of every process
repeat with i in procList
if word 1 of i is "BOMArchiveHelper" then set isRunning to true
end repeat
end repeat
Unfortunately, that doesn’t seem to slow it down at all. I put a “display alert i” inside that inner repeat so I could see what processes were running, but anything BOM related never came up. Does anybody have any ideas as to what I can do to delay the termination of my script till the ArchiveHelper quits, meaning decompression is finished? Delaying the end of the script is an effective way to tell my widget decompression is completed, as I can have certain commands run once the applescripts are completed.
If BOMArchiveHelper is running this will loop until it quits:
tell application "System Events"
repeat
if name of every process does not contain "BOMArchiveHelper" then exit repeat
end repeat
end tell
You would want to make sure that BOMArchiveHelper has started before doing this. Otherwise you may have passed this point before it launches:
tell application "System Events"
repeat
if name of every process contains "BOMArchiveHelper" then exit repeat
end repeat
repeat
if name of every process does not contain "BOMArchiveHelper" then exit repeat
end repeat
end tell
Works great! Thanks a bundle! Actually in afterthought, what if the loop starts running too late? What if the program unstuffs quickly before it gets to the first repeat loop? Is there a way to ensure that the checking happens in the right order? I’m worried that the unstuffing taking too short a time could start an endless loop.
This is all not really reliable, and a bit of a hack. Why not script the command line unzip command? Your script will wait for that to finish before going to the next iteration or past the loop block itself.
I would be using that, or ideally even gzip or better, but the files I’ll be processing have resource forks. I have to use the BOMArchive Helper to successfully reconstruct those files after being zipped.
So an addendum to my earlier issue (figured I’d just gravedig this rather than post a new topic):
My entire script that runs is as follows:
tell application "Finder"
try
set theFileList to ((every file in (("/tmp/ZipFolder" as POSIX file) as alias)) whose name extension contains "ZIP")
repeat with theItem in theFileList
open theItem using (("/System/Library/CoreServices/BOMArchiveHelper.app" as POSIX file) as alias)
tell application "System Events"
repeat
if name of every process contains "BOMArchiveHelper" then exit repeat
end repeat
repeat
if name of every process does not contain "BOMArchiveHelper" then exit repeat
end repeat
end tell
end repeat
on error theError
do shell script "echo ERR-" & theError
end try
end tell
And it works fine. I have 2 issues though. 1) I can’t process the files all at once or even too quickly separately. If I try to do it all at once, BOMArchiveHelper errors, telling me my files are bad, even though if I then try again with just that 1 file it works fine. This is the only safe way I’ve found of being able to do all the files, by making sure the BOM only handles one at a time. I just wish I could do it all at once, cause that double repeat loop leaves me with about 3 seconds of dead time between files getting unstuffed.
This script is for a bit of distribution as part of a widget, yet I have an odd problem. I’ve found that on a lot of machines I try it on, the script doesn’t run the first time, causing the files to never get decompressed. After trying it again, the script runs fine and everything gets unstuffed, but for some reason the very first attempt never occurs (happened on 2 different machines). Any idea why that would happen? What would need a jump start to get going?
I changed a bit the script architecture and here it worked at first time.
tell application "Finder"
try
--set theFileList to ((every file in (("/tmp/ZipFolder" as POSIX file) as alias)) whose name extension contains "ZIP")
set theFileList to every file in folder "Yvan_3:Users:yvankoenig:Desktop:dossier sans titre:" whose name extension contains "ZIP"
set bomBom to (("/System/Library/CoreServices/BOMArchiveHelper.app" as POSIX file) as alias)
on error theError
do shell script "echo ERR-" & theError
end try
end tell
try
repeat with theItem in theFileList
tell application "Finder" to open theItem using bomBom
tell application "System Events"
repeat
if name of every process contains "BOMArchiveHelper" then exit repeat
end repeat
repeat
if name of every process does not contain "BOMArchiveHelper" then exit repeat
end repeat
end tell -- to System Events
end repeat
on error theError
do shell script "echo ERR-" & theError
end try
Yvan KOENIG (from FRANCE jeudi 26 octobre 2006 20:17:18)