applescript

Applescripts `data size` command always returns 0 bytes


I tried to execute the data size command with applications, folders and files, but every time it returned 0 bytes.

tell application "Finder"
    set appPath to POSIX file "/Applications/Slack.app"
    set appSize to data size of appPath as application
    display dialog "The application size is " & appSize & " bytes."
end tell

However, if you look in details of the app it shows 444,6 МB.


Solution

  • Insert 'file' before the variable to get the command to work, like so:

    tell application "Finder"
        set appPath to POSIX file "/Applications/TextEdit.app"
        
        data size of file appPath
    end tell
    

    However, I am not sure that it produces a correct answer.

    You can also get either (or both) of the size properties.

    tell application "Finder"
        set appPath to POSIX file "/Applications/TextEdit.app"
        
        -- gets all of the file's properties as a record
        properties of file appPath
        --> {class:application file, name:"TextEdit.app", index:77, displayed name:"TextEdit", name extension:"app", extension hidden:true, container:folder "Applications" of startup disk of application "Finder", disk:startup disk of application "Finder", position:{389, 1160}, desktop position:missing value, bounds:{357, 1128, 421, 1192}, kind:"Application", label index:0, locked:false, description:missing value, comment:"", size:6222681, physical size:4403200, creation date:date "Wednesday, August 3, 2016 at 10:17 ", modification date:date "Monday, July 31, 2017 at 4:47 ", icon:missing value, URL:"file:///Applications/TextEdit.app", owner:"system", group:"root", owner privileges:read write, group privileges:read only, everyones privileges:read only, file type:"APPL", creator type:"ttxt", stationery:false, product version:"", version:"", id:"com.apple.TextEdit", accepts high level events:true, has scripting terminology:true}
        
        -- after reading the above, you can see that there are two size properties to get
    
        size of file appPath -- logical size of the item
        --> 6222681
        
        physical size of file appPath -- actual space used by the item on disk
        --> 4403200
        
        -- odd result when using `data size`    
        data size of file appPath
        --> 260
        
    end tell