AppleScript 中选择文件的文件夹路径

发布于 2024-12-18 15:32:27 字数 632 浏览 1 评论 0原文

我正在创建简单的脚本来使用 shell 脚本转换 mp3 文件。我决定使用 applescript 自动进行转换。 基本上我正在做的是选择 mp3 文件,然后使用命令行分割该文件,我想创建一个文件所在的文件夹(脚本将为我创建该文件夹)。

现在我只需要弄清楚如何获取文件文件夹的路径。 我如何在 applescript 中做到这一点?

这是我到目前为止所拥有的脚本:

set mp3FileToSplit to choose file without invisibles
set thepath to mp3FileToSplit as text
set theposix to POSIX path of thepath

tell application "Finder" to set file_name to (name of mp3FileToSplit)

do shell script "/opt/local/bin/mp3splt -t 3.00 -d  " & quoted form of file_name & " " & quoted form of theposix

现在该脚本的作用是在我的硬盘驱动器的根目录上创建文件夹,并且我需要位于该文件所在的文件夹中。

任何帮助将不胜感激。

I'm creating simple script to convert mp3 files using shell script. I decided to automate my conversion using applescript.
Basically what I'm doing is selecting mp3 file then splitting that file using my command line and i want to create a folder where the file is located (script will create that for me).

Now I just need to figure out how to get a path to a folder of the file.
How do I do that in applescript?

Here is the script that I have so far:

set mp3FileToSplit to choose file without invisibles
set thepath to mp3FileToSplit as text
set theposix to POSIX path of thepath

tell application "Finder" to set file_name to (name of mp3FileToSplit)

do shell script "/opt/local/bin/mp3splt -t 3.00 -d  " & quoted form of file_name & " " & quoted form of theposix

Right now what that script does is creating folder on the root of my hard drive and I need to be in the folder where the file is located.

Any help will be appreciated.

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

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

发布评论

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

评论(1

凝望流年 2024-12-25 15:32:27
tell application "Finder"
    set f to POSIX file "/private/etc/" as alias
    POSIX path of ((folder of f) as alias) -- /private/
end tell

或者

do shell script "dirname /private/etc/" -- /private
tell application "Finder"
    set f to POSIX file "/private/etc/" as alias
    POSIX path of ((folder of f) as alias) -- /private/
end tell

Or

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