Subject22 Posted June 14, 2014 Share Posted June 14, 2014 When running this workflow I see the following error in Alfred's debug pane. No output makes it to the notification action. [ERROR: alfred.workflow.action.applescript] { NSAppleScriptErrorAppName = "Alfred 2"; NSAppleScriptErrorBriefMessage = "every item of trash doesn\U2019t understand the \U201ccount\U201d message."; NSAppleScriptErrorMessage = "every item of trash doesn\U2019t understand the \U201ccount\U201d message."; NSAppleScriptErrorNumber = "-1708"; NSAppleScriptErrorRange = "NSRange: {425, 14}"; } Hard coding a value for the relevant line causes the workflow to run fine. The script runs fine in AppleScript editor (although bizarrely it gives a value of zero for the number of items in my trash - so if anyone knows why that is I'd be grateful for their input). Link to comment
Carlos-Sz Posted June 14, 2014 Share Posted June 14, 2014 (edited) When running this workflow I see the following error in Alfred's debug pane. No output makes it to the notification action. Hard coding a value for the relevant line causes the workflow to run fine. The script runs fine in AppleScript editor (although bizarrely it gives a value of zero for the number of items in my trash - so if anyone knows why that is I'd be grateful for their input). The code below seems to work (does not verify if trash is empty): set trash_size to (do shell script "du -sk ~/.Trash/ | awk '{print $1}'") as integer set units to {"KB", "MB", "GB", "TB"} set i to 1 repeat while trash_size is greater than 1000 set trash_size to trash_size / 1000 set i to i + 1 end repeat set trash_size to roundTo(trash_size, 1) tell application "Finder" to set num_items to count (every item in trash) trash_size & item i of units & " for " & (num_items) & " items" as string on roundTo(n, numDecimals) set x to 10 ^ numDecimals (((n * x) + 0.5) div 1) / x end roundTo Note that I set i to 1 initially and call Finder to get trash items. Edited June 14, 2014 by Carlos-Sz Subject22 1 Link to comment
Subject22 Posted June 14, 2014 Author Share Posted June 14, 2014 Awesome! Thank you! Any idea what I was doing wrong? Both for the error message and the 0 count for items in the trash. Link to comment
Carlos-Sz Posted June 15, 2014 Share Posted June 15, 2014 Awesome! Thank you! Any idea what I was doing wrong? Both for the error message and the 0 count for items in the trash. Having a very small file in trash lead the 'i' equal to zero which is not a valid index in your units list. In addition you have to ask Finder about trash items which the original code didn't. Link to comment
Subject22 Posted June 15, 2014 Author Share Posted June 15, 2014 But why did the same code run fine in AppleScript Editor and not in Alfred? That's interesting. Is that a recent(ish) change? I found numerous bits of code online for getting the number of items in the trash via AppleScript and none of them asked the Finder. Link to comment
Carlos-Sz Posted June 15, 2014 Share Posted June 15, 2014 The original code didn't work in my AppleScript Editor (Script Debugger). But why did the same code run fine in AppleScript Editor and not in Alfred? That's interesting. Is that a recent(ish) change? I found numerous bits of code online for getting the number of items in the trash via AppleScript and none of them asked the Finder. Link to comment
Subject22 Posted June 15, 2014 Author Share Posted June 15, 2014 Huh. It worked just fine in mine. No errors. Weird. Link to comment
Carlos-Sz Posted June 16, 2014 Share Posted June 16, 2014 Huh. It worked just fine in mine. No errors. Weird. If I run the original code in AppleScript Editor the "(count of items) in trash” returns zero items but if I type “tell application Finder” then it will return the number of items in trash properly. Anyway, I don’t know why AppleScript Editor is not showing an error. Link to comment
Subject22 Posted June 16, 2014 Author Share Posted June 16, 2014 Oh right, yes. I was getting a value of zero returned too. Just no error. Thanks again! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now