applescript 帮助命名 .plist 和删除扩展名
applescript help naming .plist and removing extention
我正在创建一个 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"
结束告诉
您可以在使用 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
det 路径。
我正在创建一个 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" 结束告诉
您可以在使用 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
det 路径。