如何获得文件名,而不从Omnigraffle延期? [英] How to get filename without extension from Omnigraffle?
问题描述
我想获得的文件名而不Omnigraffle专业5当前文档文件的扩展名。
I'm trying to get the filename without the extension of the current document file in Omnigraffle Professional 5.
tell application "OmniGraffle Professional 5"
set _document to front document
set _path to path of _document
-- Get filename without extension
tell application "Finder"
set {_filename, _extension, _ishidden} to the
{displayed_name, name_extension, extension_hidden} of the _path
end tell
end tell
这使我有以下错误:错误无法得到DISPLAYED_NAME \\的/用户/ CA /下载/月8.graffle \\。从DISPLAYED_NAME/用户/ CA /下载/月8.graffle
。
我发现了一些相关的问题和页面,但我有点失落,真的不明白为什么这是行不通的。
I found some related questions and pages, but I'm a bit lost and really can't understand why it does not work.
- Applescript: Get filenames in folder without extension
- Applescript Help...Just the File Name
感谢您的帮助!
推荐答案
您会需要将其更改为以下内容:
You'd need to change it to the following:
tell application "OmniGraffle Professional 5"
set _document to front document
set _path to path of _document
-- Get filename without extension
tell application "Finder"
set {_filename, _extension, _ishidden} to the ¬
{displayed name, name extension, extension hidden} ¬
of ((the _path as POSIX file) as alias)
end tell
if (_extension ≠ missing value) then
set baseName to text 1 thru -((length of _extension) + 2) of _filename
end if
end tell
前的文件路径返回一个文件,它只是一个简单的字符串的POSIX路径。为了能够得到一个项目在Finder会希望有一个别名引用到有问题的文件信息。当你传递一个普通的字符串,因为一个普通字符串不会有这些属性它会得到一个错误。为了得到一个别名,你需要先要挟平坦的路到POSIX文件,然后将POSIX文件强制一个别名。
"path of front document" returns the POSIX path of a file, which is just a plain string. To be able to get information on an item the Finder will want an alias reference to the file in question. When you pass a plain string it gets an error because a plain string won't have those properties. To get an alias, you need to coerce the plain path first to a POSIX file and then coerce the POSIX file to an alias.
除非你在别处定义了这些变量,你需要删除{ DISPLAYED_NAME
, name_extension
下划线, extension_hidden
}。当你在看编译code。与留在这些下划线,它看起来像下面的图片中:
Unless you have defined these variables elsewhere, you need to remove the underscores in {displayed_name
, name_extension
, extension_hidden
}. When you look at the "compiled" code with those underscores left in, it looks like in the following image:
所以,AppleScript的是间preting DISPLAYED_NAME
是一个变量,而不是一个属性。现在,这很好,如果您在别处定义的那些变量,如在性能脚本的顶部。但是,如果没有,你需要删除下划线,为Finder项属性名称不具有下划线在其中。当您删除下划线,着色出现正确的(属性紫变量是绿色的)。
So, the AppleScript is interpreting displayed_name
to be a variable, not a property. Now, that's fine if you've defined those variables elsewhere, such as at the top of your script in properties. But if not, you need to remove the underscores, as the property names of Finder items don't have underscores in them. When you remove the underscores, the coloring appears correct (properties are purple with the variables being green).
请注意,仍然不会给你的文件名没有扩展名。为了得到这一点,你就需要做一些像我使用的确在增加行文本ñ直通米
Note that that still won't give you the filename without an extension. To get that, you'd need to do something like I did in the added line using text n thru m
if (_extension ≠ missing value) then
set baseName to text 1 thru -((length of _extension) + 2) of _filename
end if
这篇关于如何获得文件名,而不从Omnigraffle延期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!