파일이없는 경우 강제 변환 as alias
이 오류를 발생시키기 때문에 코드가 실패합니다.
은이 파일에 텍스트를 작성하는 일반적인하고 신뢰할 수있는 방법입니다
set plistfilename to (path to desktop as text) & "plistfile.plist"
set ptext to "plist text"
try
set fileDescriptor to open for access file plistfilename with write permission
write ptext to fileDescriptor as «class utf8»
close access fileDescriptor
on error
try
close access file plistfilename
end try
end try
편집 :
스크립트의 결과가 간단한 .txt
파일 당신이 .plist
을 통과하더라도 것을 고려 신장.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>booleanKey</key>
<true/>
<key>stringKey</key>
<string>plist text</string>
</dict>
</plist>
:
tell application "System Events"
set rootDictionary to make new property list item with properties {kind:record}
-- create new property list file using the empty dictionary list item as contents
set the plistfilename to "~/Desktop/plistfile.plist"
set plistFile to ¬
make new property list file with properties {contents:rootDictionary, name:plistfilename}
make new property list item at end of property list items of contents of plistFile ¬
with properties {kind:boolean, name:"booleanKey", value:true}
make new property list item at end of property list items of contents of plistFile ¬
with properties {kind:string, name:"stringKey", value:"plist text"}
end tell
스크립트 프로퍼티리스트 파일을 생성합니다
는
System Events
당신이 사용할 수있는
실제 속성 목록 파일을 만들려면