如何将AppleScript路径转换为posix路径并传递给shell脚本? [英] How to turn an AppleScript path into a posix path and pass to shell script?

查看:346
本文介绍了如何将AppleScript路径转换为posix路径并传递给shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个我的ffmpeg命令可以合并两个视频文件的文本文件。我遇到的问题是让我的文件夹/文件路径看起来像我想要的。导致我的问题的两行是:

I´m trying to create a textfile that my ffmpeg-command can use to merge two videofiles. The problem I´m having is getting my folder/file-paths to look like I want. The two lines that cause my problems are:

将文件设置为replay_folder& ls.txt

我只想让这条路径成为 replay_folder ls.txt

I simply want this path to be the path of replay_folder and ls.txt

在shell脚本行中,我想要相同的东西。

In the shell script line I want the same thing.

做shell脚本cd& replay_folder&
/ usr / local / bin / ffmpeg -f concat -i ls.txt -c copy merged.mov

我得到这个路径与shell脚本 Macintosh HD:用户:BjornFroberg:文件:wirecast:Replay-2017-03-17-12_11-1489749062:

I get this path with the shell script Macintosh HD:Users:BjornFroberg:Documents:wirecast:Replay-2017-03-17-12_11-1489749062:

但是我想要这个 / Users / BjornFroberg / Documents / wirecast / Replay-2017-03-17-12_11-1489749062 /

完整的代码是:

tell application "Finder"
set sorted_list to sort folders of folder ("Macintosh HD:Users:bjornfroberg:documents:wirecast:") by creation date
set replay_folder to item -1 of sorted_list
set replay_files to sort items of replay_folder by creation date
end tell

set nr4 to "file '" & name of item -4 of replay_files & "'"
set nr3 to "file '" & name of item -3 of replay_files & "'"

set theText to nr4 & return & nr3

set overwriteExistingContent to true

set theFile to path to replay_folder & "ls.txt" --actual path is: POSIX file "/Users/BjornFroberg/Documents/wirecast/Replay-2017-03-17-12_11-1489749062/ls.txt"

set theOpenedFile to open for access file theFile with write permission

if overwriteExistingContent is true then set eof of theOpenedFile to 0

write theText to theOpenedFile starting at eof

close access theOpenedFile

do shell script "cd " & replay_folder & "
/usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov"

任何帮助不胜感激:)

推荐答案

路径到是标准脚本添加的一部分,仅适用于预定义的文件夹。它不适用于自定义路径。例如Macintosh HD:Users:bjornfroberg:documents:可以替换为相对路径

path to is part of Standard Scripting Additions and works only with predefined folders. It does not work with custom paths. For example "Macintosh HD:Users:bjornfroberg:documents:" can be replaced with the relative path

set documentsFolder to path to documents folder as text

当前用户的文档文件夹。

which points always to the documents folder of the current user.

replay_folder 是一个Finder对象说明符,可以在这里特定的形式 - 只能被做为Finder。要创建(冒号分隔) HFS路径,您需要将Finder说明符强制转换为文本

replay_folder is a Finder object specifier which can - in this particular form – only be handled be the Finder. To create an (colon separated) HFS path you need to coerce the Finder specifier to text

set theFile to (replay_folder as text) & "ls.txt" 

但是要传递 replay_folder 到shell,你必须使用 POSIX路径(斜杠分隔)。由于Finder说明符不能直接胁迫到 POSIX路径,您还需要首先创建一个 HFS路径。此外,您必须注意空间字符在路径中转义。任何未转义的空格字符将破解shell脚本

However to pass the replay_folder to the shell you have to use a POSIX path (slash separated). Since a Finder specifier cannot be coerced directly to POSIX path you need also first create a HFS path. Additionally you have to take care that space characters are escaped in the path. Any unescaped space character will break the shell script

set replay_folderPOSIX to POSIX path of (replay_folder as text)
do shell script "cd " & quoted form of replay_folderPOSIX & "
/usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov"

这篇关于如何将AppleScript路径转换为posix路径并传递给shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆