我正在尝试创建一个文本文件,我的ffmpeg命令可以用来合并两个视频文件。我遇到的问题是让我的文件夹/文件路径看起来像我想要的那样。引起我问题的两条线是:
set theFile to path to replay_folder & "ls.txt"
我只是希望此路径成为replay_folder
和ls.txt
在shell脚本行中我想要同样的东西。
do shell script "cd " & replay_folder & "
/usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov"
我使用shell脚本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"
感谢任何帮助:)
答案 0 :(得分:2)
您可以将AppleScript路径转换为Posix路径,如下所示:
set applescriptPath to "Macintosh HD:Users:bjornfroberg:documents:wirecast:"
set posixPath to (the POSIX path of applescriptPath)
log posixPath
返回/Users/bjornfroberg/documents/wirecast/
注意:您的帖子标题和实际问题是不同的主题。您的目标是将AppleScript路径(Macintosh HD:Users:bjornfroberg:documents:wirecast
)转换为要添加文件名的posix路径(/Users/bjornfroberg/documents/wirecast/
);您可以将上面的代码与现有代码结合使用来构建完整路径:
set theFile to POSIX path of (replay_folder as text) & "ls.txt"
根据您要执行的操作,一旦定义了路径,您可能需要将其转换为posix 文件以通过AppleScript操作它。例如,如果要通过AppleScript打开它:
set pFile to POSIX file theFile
tell application "Finder" to open pFile
(见POSIX path in applescript from list not opening. Raw path works)
答案 1 :(得分:1)
path to
是标准脚本添加的一部分,仅适用于预定义文件夹。它不适用于自定义路径。例如,"Macintosh HD:Users:bjornfroberg:documents:"
可以用相对路径
set documentsFolder to path to documents folder as text
始终指向当前用户的文档文件夹。
replay_folder
是一个Finder对象说明符,它可以 - 以这种特殊的形式 - 只能被Finder处理。要创建(冒号分隔的) HFS路径,您需要将Finder说明符强制为文本
set theFile to (replay_folder as text) & "ls.txt"
但是要将replay_folder
传递给shell,您必须使用 POSIX路径(斜线分隔)。由于Finder说明符无法直接强制转换为POSIX path
,因此您还需要先创建HFS path
。此外,您必须注意在路径中转义空格字符。任何未转义的空格字符都会破坏shell脚本
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"