我想從CSV文件讀取並將AppleScript中的變量與CSV文件的內容進行比較。下面的文件和變量的例子。在AppleScript中解析CSV文件並選擇列
CSV文件:
GroupName, DriveLetter, Path
Test1 , E: , \\networkshare\test1
Test4 , G: , \\networkshare\test4
的AppleScript變量包含:
Test1
Test2
Test3
如果變量和CSV文件(如Test1的),我需要選擇具有相關聯的路徑之間的匹配Test1行並將其保存到一個新變量,然後使用該變量映射一個卷。
這裏是腳本的一個片段:
set current_user to system attribute "USER" as text
set command to do shell script ("dscl '/Active Directory/DOMAIN/All Domains' -read /Users/" & current_user & " dsAttrTypeNative:memberOf")
set group to trim_line(command, "dsAttrTypeNative:memberOf:", 0)
mount volume "smb://servername/netlogon/"
set DrivesFile to (read "/volumes/netlogon/drives.csv" using delimiter {",", lf})
repeat with aline in DrivesFile
if aline is in group then "this is where I need to select the other CSV column and then mount a volume"
end repeat
'trim_line'是一個自定義函數嗎?它返回什麼? 「Test1」等?我是否正確理解變量「group」包含在您的問題中標記爲「CSV文件」的數據?如果仔細觀察trim_line,您應該能夠理解行和分隔符如何工作。如果沒有人比我快,我會嘗試發表一個例子。 – Mark