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

Convert Unicode to text?

I have this little script that searched for files


set tc to countspotlightqueryList

set theseCount to {}

repeat tc times

set end of theseCount to 0

end repeat



repeat with i in thefolders

set thepath to my existsItem(tHome & i)

if thepath is not "" then -- exists

repeat with j from 1 to tc

set tQuery to itemj of spotlightqueryList

do shell script "mdfind -onlyin " & thepath & " " & tQuery & " " & thekind & " | wc -l" -- wc return the number of lines

set item j of theseCount to (item j of theseCount) + (the result as integer) -- add the number of lines


end repeat

end if


end repeat



Then I add it to the csv file


do shell script "echo " (quoted form of theseCount) & " >>" & quoted form of POSIX path of csvPath




Now when I log theseCount


the result is (*70, 369, 0, 141, 113, 45*)


error "Can’t make quoted form of {70, 369, 0, 141, 113, 45} into type Unicode text." number -1700 from quoted form of {70, 369, 0, 141, 113, 45} to Unicode text



I need to get each value in the quoted form.


How can I do this?

Thanks

Matt

Mac Pro, OS X Mavericks (10.9)

Posted on Feb 21, 2014 1:57 AM

Reply
Question marked as Best reply

Posted on Feb 21, 2014 3:04 AM

Hello


You need to create string "70,369,0,141,113,45" from list of integers {70, 369, 0, 141, 113, 45} before passing it to "do shell script".


Something like this.


set theseCount to {70, 369, 0, 141, 113, 45}
set s to _join(",", theseCount)
do shell script "echo " & s's quoted form & ">> ~/desktop/test.csv"

on _join(d, tt)
    (*
        string d : separator
        list tt : source list
        return string : tt joined with d
    *)
    local astid0, t
    try
        set {astid0, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {} & d}
        set t to "" & tt
        set AppleScript's text item delimiters to astid0
    on error errs number errn
        set AppleScript's text item delimiters to astid0
        error errs number errn
    end try
    return t
end _join


Regards,

H

4 replies
Question marked as Best reply

Feb 21, 2014 3:04 AM in response to MattJayC

Hello


You need to create string "70,369,0,141,113,45" from list of integers {70, 369, 0, 141, 113, 45} before passing it to "do shell script".


Something like this.


set theseCount to {70, 369, 0, 141, 113, 45}
set s to _join(",", theseCount)
do shell script "echo " & s's quoted form & ">> ~/desktop/test.csv"

on _join(d, tt)
    (*
        string d : separator
        list tt : source list
        return string : tt joined with d
    *)
    local astid0, t
    try
        set {astid0, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {} & d}
        set t to "" & tt
        set AppleScript's text item delimiters to astid0
    on error errs number errn
        set AppleScript's text item delimiters to astid0
        error errs number errn
    end try
    return t
end _join


Regards,

H

Feb 21, 2014 4:14 AM in response to MattJayC

When working with a List, go through the items using a repeat loop:


set csvPath to "~/Desktop/Test.csv"

set theseCount to {70, 369, 0, 141, 113, 45}


repeat with i from 1 to the count of theseCount

do shell script "/bin/echo -n " & item i of theseCount & ", >>" & csvPath

end repeat

do shell script "echo >>" & csvPath-- add newline


For more List Sub-Routines see: List Manipulation Routines

Feb 21, 2014 8:48 AM in response to Tony T1

To reduce the calls to do shell script :


set csvPath to "~/Desktop/Test.csv"

set theseCount to {70, 369, 0, 141, 113, 45}


setthisLineto ""

repeatwithifrom 1 tothecountoftheseCount

set thisLine to thisLine & itemi of theseCount & ","

end repeat

do shell script "echo " & thisLine & ">>" & csvPath

setthisLineto "" -- reset variable

Feb 21, 2014 9:15 AM in response to MattJayC

or just

set itemSeperator to "," -- set to the seperator you want for each item


set theseCount to {70, 369, 0, 141, 113, 45}


set {oldTID, my text item delimiters} to {my text item delimiters, itemSeperator} -- save old delimiter, set new one


set s to theseCount as text


set my text item delimiters to oldTID -- set delimiter back to what it was

s will contain the string of numbers separated by (in this case) commas

Convert Unicode to text?

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