我正在创建一个AppleScript来创建一个带有属性列表元素但没有.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" 结束告诉
答案 0 :(得分:1)
您可以通过Finder(set name extension of file "Hfs:path:to:file:with:name.ext" to "new-ext"
)完成系统事件处理后再实现。
但是我不确定您是否可以期望系统事件将该文件视为属性列表文件,之后包含属性列表项。不过还是值得一试的。 :)
这是您必须更改名称扩展名的方式,因为这不适用于系统事件(名称扩展名为只读属性)。
tell application "Finder"
set mf to (path to desktop folder as text) & "labels.txt"
set name extension of file mf to "text"
end tell
使用文件的 HFS路径,又名:Macintosh Hd:Users:You:path:file.ext,而不是posix路径。并且不使用quoted form of
路径。