Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Can't make ... into type number

A script of mine contains:


set duration to (word -2 of (do shell script "/usr/bin/afinfo " & eachFile & "|grep duration")) as number


Where eachFile is a .m4r file that the user has been asked to select. I've always been able to execute this script without error, but some others who have used it report that they get an error message such as: "Can't make 10.94778 into type number." I assume it has to do with the above line, but I cannot think of how to fix the issue, especially since I am unable to reproduce it.

 MacBook Pro with Retina display-OTHER, OS X Mavericks (10.9.5), 15 in, Late 2013, 256GB, 8GB RAM

Posted on Sep 27, 2015 11:58 AM

Reply
4 replies

Sep 27, 2015 1:44 PM in response to stevejobsfan0123

Decimal separator is locale dependent and thus AppleScript's string-to-number and number-to-string conversions are locale dependent. You need to take care of it before coercing string to number in AppleScript. Something like this.



set f to "/path/to/audio/file" if "," is in (0.0 as string) then (do shell script "afinfo " & f's quoted form & " | sed -En '/duration/ { s/.* ([0-9.]+) .*/\\1/ s/\\./,/p }'") as number else (do shell script "afinfo " & f's quoted form & " | sed -En '/duration/ { s/.* ([0-9.]+) .*/\\1/p }'") as number end if



H

Can't make ... into type number

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.