Saturday, December 16, 2017

#1 2017-10-30 06:38:33 pm

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 541
Website

Busy status when unzipping

Hi there,
How to get the right amount of delay / busy status of :

Applescript:

set zip_file to "path:to:foo.zip"
tell application "System Events"
open alias zip_file
delay 2
delete alias zip_file
end

Delay isn't precise I know but anyway... Its a static value in seconds.
The dropped directory from zip might have another name.

I think the easier way to go is in one line shell script with ";" and I get also the result (the unzipped file as string).
But I don't like to use rm in this chain hmm it's too powerful and little mistakes cause already a big mess

Last edited by Joy (2017-10-30 06:50:57 pm)

Offline

 

#2 2017-10-30 07:43:10 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Busy status when unzipping

Use do shell script and ditto. You can still use System Events for the deletion if you wish.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-11-01 04:05:43 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2727
Website

Re: Busy status when unzipping

Joy wrote:

I think the easier way to go is in one line shell script with ";" and I get also the result (the unzipped file as string).



I wouldn't use ";" for commands like these especially when they the second command only needs to run when the first exited successful.

First lets use a command return a non zero value (error).

Applescript:

do shell script "false" --result: error

Now lets use a command separator (could use newline as well).

Applescript:

do shell script "false ; echo yes" -- result: "yes"

As you can see when the first commands exists with a non-zero value, as shown in the first example, the second command is just executed. The return value of the last command is returned and it silence all errors in the previous commands.

Now let's use the AND operator to combine two commands.

Applescript:

do shell script "false && echo yes" -- result: error

The second command is now only executed when the first command exited successfully. In the example above "echo yes" is never executed. Instead of silencing previous commands when an commands returns a non-zero value the script is stopped and that value is returned. In AppleScript you will always catch the right error. In pseudo code you're looking for something like this:

Applescript:

do shell script "unzip $source $target && rm $source"

Last edited by DJ Bazzie Wazzie (2017-11-01 04:07:07 am)

Offline

 

#4 2017-11-02 01:18:13 pm

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 541
Website

Re: Busy status when unzipping

@Shane Stanley
Wow, I solved in a One-liner and replacing 4 more operations
Anyway I saw, ditto or cp don't overwrite folders but files. So it's an incremental merging, no real overwriting.

@DJ Bazzie Wazzie
Nice bits of wisdom. After a bit of testing, no command was able to give me the result of open (=> dropped files) but I solved with isolating in temporary items
I found no way around to get the amount of time that open needs to decompress a rar 
Fortunately, rar didn't matter for the final outcome of my code, so zip were used instead.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)