I’m trying to modify the result of “usr/bin/uptime” from something like “10:42 up 1 day, 3 mins, 2 users, load averages: 0.15 0.14 0.14” to just “1 day, 3 min” or something to that effect.
Could someone point me in the right direction?
I’m trying to modify the result of “usr/bin/uptime” from something like “10:42 up 1 day, 3 mins, 2 users, load averages: 0.15 0.14 0.14” to just “1 day, 3 min” or something to that effect.
Could someone point me in the right direction?
Depends on how consistent the wording is. Will words 3 through 6 of theResult do it? If not, you can parse strings by setting applescript’s text item delimitters and then asking for text items of theResult. i.e set delims to a comma and then set theResult to (text items 2 through 3 of theResult) as string.
That’ll do it.
Ok, thanks . That worked quite well!
That might work quite well for now, but it won’t work if you rebooted your machine less than 24 hours prior to running the script. That’s because the command doesn’t output the number of days if that number is less than 1.
In lieu of finding a more direct method, your script should include some error checking (e.g. does the string contain ‘day’) and adjust accordingly.