如何将AppleScript路径转换为posix路径并传递给shell脚本?

如何将AppleScript路径转换为posix路径并传递给shell脚本?,shell,ffmpeg,applescript,Shell,Ffmpeg,Applescript,我正在尝试创建一个文本文件,我的ffmpeg命令可以用来合并两个视频文件。我遇到的问题是让我的文件夹/文件路径看起来像我想要的。导致我的问题的两条线是: 将文件设置为重播文件夹的路径&“ls.txt” 我只想让这个路径成为replay\u文件夹和ls.txt 在shell脚本行中,我想要相同的东西 do shell脚本“cd”&replay\u文件夹&” /usr/local/bin/ffmpeg-f concat-i ls.txt-c copy merged.mov“ 我通过shell脚本Ma

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

将文件设置为重播文件夹的路径&“ls.txt”

我只想让这个路径成为
replay\u文件夹
ls.txt

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

do shell脚本“cd”&replay\u文件夹&”
/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"

非常感谢您的帮助:)

您可以将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

(请参阅)

您可以将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

(请参阅)

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

set documentsFolder to path to documents folder as text
始终指向当前用户的文档文件夹


replay_folder
是一个Finder对象说明符,在这种特殊形式下,它只能由Finder处理。要创建(冒号分隔)HFS路径,需要强制查找器说明符为文本

set theFile to (replay_folder as text) & "ls.txt" 
但是,要将
replay_文件夹
传递给shell,必须使用POSIX路径(斜杠分隔)。由于查找器说明符不能直接强制到
POSIX路径
,因此还需要首先创建
HFS路径
。此外,还必须注意在路径中转义空格字符。任何未换格的空格字符都将破坏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"

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

set documentsFolder to path to documents folder as text
始终指向当前用户的文档文件夹


replay_folder
是一个Finder对象说明符,在这种特殊形式下,它只能由Finder处理。要创建(冒号分隔)HFS路径,需要强制查找器说明符为文本

set theFile to (replay_folder as text) & "ls.txt" 
但是,要将
replay_文件夹
传递给shell,必须使用POSIX路径(斜杠分隔)。由于查找器说明符不能直接强制到
POSIX路径
,因此还需要首先创建
HFS路径
。此外,还必须注意在路径中转义空格字符。任何未换格的空格字符都将破坏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"