Find Jobs
Hire Freelancers

Applescript isDone() integration

€8-30 EUR

Completed
Posted over 3 years ago

€8-30 EUR

Paid on delivery
I have an Applescript who measure the phisical size of each pdf in the target folder an create a csv file. I need to add a check if the files are finished writing to disk before to start to measure each file. I founded this code who may help but I need someone to integrate it in my Applescript: (* isDone() Checks if a file has finished writing to disk. Parameters: File2Check: file path, alias, posix path LastFileSize: initialize with -1; seed each subsequent call with the return of the previous LastFileSize Returns: 2 item list: item 1 - true or false item 2 - the CurrentFileSize as integer++ (++ returns -1 if file does not exist) Examples: isDone("path:to:[login to view URL]", -1) --> {false, 6207} == file not done. isDone("path:to:[login to view URL]", 39402708) --> {false, -1} == file write aborted??? isDone("path:to:[login to view URL]", LastFileSize) --> {true, 564689207} == file is done. written by Jeff Case 2004 *) property StillGrowing : null property CurrentFileSize : null --property File2Check : "JData:Downloads:[login to view URL]" --property LastFileSize : -1 on run {File2Check, LastFileSize} tell application "Finder" if alias File2Check exists then else return {false, -1} end if end tell set File2Check to File2Check as Unicode text set StillOpen to isOpen(File2Check) isGrowing(File2Check, LastFileSize) if StillGrowing is false then return {true, CurrentFileSize} else return {false, CurrentFileSize} end if if StillOpen is false and StillGrowing is false then return {true, CurrentFileSize} else return {false, CurrentFileSize} end if end run on isOpen(File2Check) -- check the "open" status of the file -- thanks to captnswing for the 'lsof' command -- works on SMB transfers set ItzOpen to ((do shell script ("echo `lsof " & (quoted form of (POSIX path of (File2Check))) & " | wc -l`")) as integer) if ItzOpen = 0 then return false else return true end if end isOpen on isGrowing(File2Check, LastFileSize) -- parse the return of "ls" for the current file size - NOT the Finder -- sometimes it reports back as 0 even though some data has written -- so this waits for a valid "size" report from "ls" -- "ls" more responsive and reliable than a Finder query set CurrentFileSize to 0 repeat while CurrentFileSize is 0 set LSreturn to do shell script ("ls -l " & (quoted form of (POSIX path of alias (File2Check)))) set AppleScript's text item delimiters to " " set CurrentFileSize to (text item 4 of LSreturn) set AppleScript's text item delimiters to " " set CurrentFileSize to ((text item 1 of CurrentFileSize) as string) as integer set AppleScript's text item delimiters to "" end repeat set AppleScript's text item delimiters to "" if CurrentFileSize > LastFileSize then set StillGrowing to true else set StillGrowing to false end if end isGrowing
Project ID: 27782073

About the project

1 proposal
Remote project
Active 4 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
❤️ Dear, How are you today? I have a rich experience in applescript. You can check my profile. Kindly provide me the details about the project. Looking forward from your end. Best regards
€50 EUR in 7 days
3.0 (3 reviews)
3.9
3.9

About the client

Flag of ITALY
Ljubljana, Italy
5.0
4
Payment method verified
Member since May 2, 2016

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.