Tuesday, September 27, 2022

#1 2022-06-27 06:00:08 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2524

How to wait until writeToFile: method competes writing?

Hello, friends.

Often I use the writeToFile: method like here:

set theArchiveData to webFrame's dataSource()'s webArchive()'s |data|()
        theArchiveData's writeToFile:thePath atomically:true
           -- the next code line


As I understand, the AppleScript interpretator continue with next code line. That is, doesn't wait for writing completion. So, how to make it to wait?

Last edited by KniazidisR (2022-06-27 06:02:12 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#2 2022-06-27 04:48:28 pm

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

Re: How to wait until writeToFile: method competes writing?

That call shouldn't return until the write is complete.


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

Offline

 

#3 2022-06-27 10:04:12 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2524

Re: How to wait until writeToFile: method competes writing?

Thanks for the clarification.

I have one script that uses a repeat loop with this method inside it. After about 50-400 iterations, the script hangs.

I assumed that the reason for the hang is in this method, but as you explained to me, now I understand that the reason is something else.


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#4 2022-06-28 01:26:25 am

technomorph
Member
Registered: 2017-12-14
Posts: 279

Re: How to wait until writeToFile: method competes writing?

I thought they were depricating this for writeToURL
As I was going to suggest that.
But they haven’t :
https://developer.apple.com/documentati … ritetofile

You’ll notice that it returns a BOOL value to let
You know if the save worked. 
You might want to add that to your code,
You’ll know when it completed and if it was
Successful.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)