在我的脚本中,我获取应用程序的 UI 元素属性,并将其以列表的形式保存在变量中。我想将此变量保存到文本文件中。我该怎么做?
答案1
您可以尝试以下方法:
-- Example elements
tell application "System Events" to tell process "Finder"
set uiElements to (get UI elements)
end tell
set uiTextList to {}
repeat with uiE in uiElements
try
set uiText to uiE as text
set end of uiTextList to uiText
on error errMsg
set {TID, text item delimiters} to {text item delimiters, {"Can’t make ", " into type text."}}
set end of uiTextList to text item 2 of errMsg
set text item delimiters to TID
end try
end repeat
do shell script "echo " & quoted form of (uiTextList as text) & " > " & quoted form of POSIX path of (path to desktop as text) & "log.txt"
答案2
尝试一下这个方法:
set the textFile to ((path to desktop) as text) & "filename.txt"
open for access file the textFile with write permission
write ("Whatever you want to write" & return) to file the textFile starting at eof
close access file the textFile