Jump to content

need help with script - either shell or applescript

4 posts in this topic

Recommended Posts

ok, so what i want to do is make some sort of script, either applescript or shell script, that will do the following:


take out from a command in the terminal

put that output into a text file already on my computer.


the only thing is that i need to put the output in the file kinda weird: i need to take it and put each character of output on a new line, but not create new lines




take output of command 'uptime' (up 32 days, 23:09)

place in file 'myFile'




key u

key p

key space

key 3

key 2

key space

key d



anyone have any idea on how to do this?


thanks in advance

Link to comment
Share on other sites

  • 3 weeks later...

Quick and dirty way with bash:



while [ $upTimeIndex -le $upTimeLength ]; do
 echo ${upTime:$upTimeIndex:1} >> tmpfile.txt
 let upTimeIndex=upTimeIndex+1



Link to comment
Share on other sites

And a quick and dirty AppleScript.


Save this as an app in Script Editor and execute from the Finder:


set myText to ""
set theFile to "tmpfile2.txt" as file specification
set upTime to do shell script ("uptime")
set upTimeLength to the number of characters of upTime
set upTimeIndex to 1

repeat while upTimeIndex is less than or equal to upTimeLength
set myText to myText & (character upTimeIndex of upTime) & return
set upTimeIndex to upTimeIndex + 1
end repeat

open for access theFile with write permission
write myText to theFile starting at eof as text
close access theFile



Link to comment
Share on other sites


  • Create New...