applescript 摆脱完整路径

发布于 2024-12-18 05:08:19 字数 583 浏览 5 评论 0原文

我的 AppleScript 中有一个选择文件。当我运行脚本并选择一个文件时,输出始终是完整文件路径,末尾带有文件扩展名。例如:

Macintosh HD:Developer:About Xcode.pdf

是我不想要的。我只想:

About Xcode


当其中有多个 . 时,Kassym Dorsel 的以下答案不起作用。

Lri 的以下回答不适用于 set x to select file

error "Can’t make quoted form of alias \"Macintosh HD:Applications:Firefox.app:\" into        type Unicode text." number -1700 from quoted form of alias "Macintosh HD:Applications:Firefox.app:" to Unicode text

I've got a choose file in my AppleScript. When I run the script and choose a file, the output is always the full file path with the file extension on the end. For example:

Macintosh HD:Developer:About Xcode.pdf

is what I don't want. I only want:

About Xcode


The below answer by Kassym Dorsel doesn't work when there is more than one . in it.

The below answer by Lri doesn't work with set x to choose file:

error "Can’t make quoted form of alias \"Macintosh HD:Applications:Firefox.app:\" into        type Unicode text." number -1700 from quoted form of alias "Macintosh HD:Applications:Firefox.app:" to Unicode text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清君侧 2024-12-25 05:08:19

您可以使用 Finder 来操作 Finder 项目的名称:

choose file with prompt "Pick one"
set filepath to result

tell application "Finder" to set {dispName, nameExt, isHidden} to ¬
    the {displayed name, name extension, extension hidden} of the filepath


if isHidden or nameExt is equal to "" then
    dispName
else
    (characters 1 through (-2 - (count of nameExt)) of dispName) as text
end if

set baseName to result

You can use the Finder to manipulate the names of Finder items:

choose file with prompt "Pick one"
set filepath to result

tell application "Finder" to set {dispName, nameExt, isHidden} to ¬
    the {displayed name, name extension, extension hidden} of the filepath


if isHidden or nameExt is equal to "" then
    dispName
else
    (characters 1 through (-2 - (count of nameExt)) of dispName) as text
end if

set baseName to result
鸢与 2024-12-25 05:08:19

这将起作用:

set a to "Macintosh HD:Developer:About.Xcode.pdf"
set text item delimiters to ":"
set temp to last text item of a
set text item delimiters to "."
set temp to text items 1 thru -2 of temp as text

给出 => 关于.Xcode

This will work :

set a to "Macintosh HD:Developer:About.Xcode.pdf"
set text item delimiters to ":"
set temp to last text item of a
set text item delimiters to "."
set temp to text items 1 thru -2 of temp as text

Gives => About.Xcode

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文