【发布时间】:2015-03-12 13:09:49
【问题描述】:
我正在创建一个苹果脚本来创建一个包含属性列表元素但没有 .plist 扩展名的文件!
我的问题是如果我使用对话框来获取文件的名称,例如。
tell application "SystemUIServer"
display dialog "Enter filename :- " buttons {"Generate file"} default answer "Generate Keyfile"
set fileName to text returned of result
然后像这样在桌面上创建文件
set text_file to (path to desktop)'s POSIX path & "" & quoted form of fileName & ".NEWextention"
最后我将元素添加到 .plist
tell application "System Events"
tell (make new property list file with properties {name:text_file})
make new property list item at end with properties {kind:string, name:"regName", value:"FOO"}
make new property list item at end with properties {kind:string, name:"regNumber", value:"BAR" as text}
end tell
end tell
end tell
但是,创建的文件在从 fileName 引用时具有 '' 并且仍然具有 .plist 扩展名。
例如输入:- myfile
output:- 'myfile'.NEWextention.plist
当我想要的时候
myfile.NEWextention
如何在 applescript 中实现这一点?
任何帮助将不胜感激! 非常感谢。
below is the fixed code thanks to @McUsr
如果没有他的帮助,我会在 6 个多月的反复试验中处于同一点
tell application "SystemUIServer"
display dialog "Enter FileName :- " buttons {"Generate file"} default answer "Generate file"
set FileName to text returned of result
set text_file to (path to desktop folder as text) & FileName & ".plist"
set dateStamp to do shell script "date"
tell application "System Events"
tell (make new property list file with properties {name:text_file})
make new property list item at end with properties {kind:string, name:"Name", value:FileName}
make new property list item at end with properties {kind:string, name:"Date", value:dateStamp}
end tell
end tell
说完
告诉应用程序“Finder” 将文件 text_file 的扩展名设置为“newExt” 结束告诉
【问题讨论】:
标签: applescript osx-yosemite info.plist