I would like to extract name from text list.
Result from do shell shell
command:
set Clist to do shell command "ls ./"
Is:
John_01044445558_pass.jpg<br>
Jane_01044562738_visa.jpg<br>
Doe_01027381938_pass.jpg<br>
Joe_7485.jpg
I need John
Jane
Doe
Joe
from that list in this format:
John, Jane, Doe, Joe
How can I achieve this?
Here is Full script.
tell application "Finder"
set fullname to name of (selection as alias)
set Cdate to do shell script "date '+%Y.%m.%d'"
set AppleScript's text item delimiters to {"_"}
if fullname contains ".jpg" then
set CnameNFD to first text item of fullname
set Cmobile to second text item of fullname
set Ccustomer to second text item of fullname
set Ctemp to "/Volumes/homes/macbook/Save/"
set Clink to "https://r.loyverse.com/dashboard/#/clients/database?page=0&limit=10&search="
set Cname to ¬
do shell script "echo " & (CnameNFD as text) & "|iconv -f UTF-8-MAC -t UTF-8"
--Save폴더에서 전화번호로 검색된리스트를 이름만 가져옴
-- set Cppl to do shell script "Ctemp=" & Ctemp & " Cmobile=" & Cmobile & ";ls $Ctemp | grep $Cmobile | awk -F'_' '{print $1}' "
set Cppl to do shell script "Ctemp=" & Ctemp & " Cmobile=" & Cmobile & ";ls $Ctemp | grep $Cmobile "
set lsOutputAsList to ¬
paragraphs of ¬
Cppl
set theNamesList to {}
repeat with thisItem in lsOutputAsList
copy first text item of thisItem ¬
to the end of theNamesList
end repeat
set AppleScript's text item delimiters to ", "
set theNames to theNamesList as text
set AppleScript's text item delimiters to {""}
do shell script "Cname=" & Cname & " Cmobile=" & Cmobile & " Ccustomer=" & Ccustomer & " theNames=" & theNames & "; echo \"'$theNames'\""
else display dialog "올바른 파일을 선택하십시오." buttons {"Okay"} default button 1 end if end tell
If I display dialog theNames it shows as I expected. But I run with shell script echo theNames it shows nothing. I need to use theNames variable to curl post.
$PWD
of ado shell script
command is/
and as such there is no way that the variableClist
inset Clist to do shell command "ls ./"
will contain the output you've shown. It will contain a listing of what is in the root of the, e.g., Macintosh HD. In other words,set Clist to paragraphs of (do shell command "ls ./")
will be:{"Applications", "Library", "System", "Users", "Volumes", "bin", "cores", "dev", "etc", "home", "opt", "private", "sbin", "tmp", "usr", "var"}
ls
. It says so in its ownman
page. Its output can vary considerably between systems, between shells, between versions of macOS, or simply between folders. Instead ofdo shell script "ls $Ctemp | grep $Cmobile"
, usedo shell script "cd \"$Ctemp\"; printf '%s\n' *\"$Cmobile\"*"
, orthe name of every file in the folder named (Ctemp as POSIX file) whose name contains Cmobile
.