简体   繁体   English

使用“ touch -r”通过自动器处理多个文件

[英]Use “Touch -r” for several files with automator

I use "MacOS X Yosemite (10.10.4)" 我使用“ MacOS X Yosemite(10.10.4)”

I've converted video mts files to mov files using QuickTime, but the new file created doesn't preserve original Creation Date. 我已经使用QuickTime将视频mts文件转换为mov文件,但是创建的新文件并未保留原始的创建日期。

fileA.mts --> Creation Date: 07/02/2010 10:51 fileA.mts->创建日期:2010年7月2日10:51

fileA_converted.mov --> Creation Date: Today 8:35 fileA_converted.mov->创建日期:今天8:35

I'd like to change the Creation Date attribute of several files, using the date of the original files. 我想使用原始文件的日期更改多个文件的创建日期属性。 I know I can do this by using Terminal "Touch" command in order to this: 我知道我可以通过使用终端“ Touch”命令来做到这一点:

touch -r fileA.mts fileA_converted.mov

touch -r fileB.mts fileB_converted.mov

As I have more than 200 files to change Creation Date, is it possible to automate this using automator Script Shell action, or any other way? 由于我有200多个文件要更改“创建日期”,是否可以使用自动脚本外壳程序操作或其他方法自动执行此操作?

Execute below command when we have all original and converted files in same folder 当所有原始文件和转换后的文件都放在同一文件夹中时,请执行以下命令

ls | grep ".mts" | awk -F. '{print $0" "$1"_converted.mov"}' |  xargs touch -r

when we have different folder run below command on path where .mts files are present and add absolute path before $1 just like I have added /home/convertedfiles/ 当我们在存在.mts文件的路径上在命令下运行以下文件夹并在$ 1之前添加绝对路径时,就像我添加了/ home / convertedfiles /

ls | grep ".mts" | awk -F. '{print $0" /home/convertedfiles/"$1"_converted.mov"}' |  xargs touch -r

Like this in the bash shell - which is what you get in Terminal (untested): bash shell中是这样的-这是您在Terminal获得的(未经测试的):

#!/bin/bash
for orig in *.mts; do 
   # Generate new name from old one
   new="${orig/.mts/_converted.mov}"
   echo touch -r "$orig" "$new"
done

Save the above in a file called doDates and then type this in the Terminal 将以上内容保存在名为doDates的文件中,然后在终端中键入

chmod +x doDates          # make the script executable
./doDates                 # run the script

Sample output 样品输出

touch -r Freddy Frog.mts Freddy Frog_converted.mov
touch -r fileA.mts fileA_converted.mov

At the moment it does nothing, but run it, see if you like what it says, and then remove the word echo and run it again if all looks ok. 目前,它什么也没做,但是运行它,看是否喜欢它所说的内容,然后删除echo一词,如果一切正常,则再次运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Automator中执行R命令 - Execute R Commands in Automator 在数十个文件上使用pdfjam - Use pdfjam on several dozens of files Automator:文件夹中文件的Shell脚本 - Automator: shell script for files in a folder 如何使用 Automator 和 Applescript 根据日历事件中的特定文本将文件/文件夹批量移动到指定文件夹,MacOS - How to use Automator and Applescript to batch move files/folders to a specified folder based on specific text in Calendar Events, MacOS 使用Automator复制文件,执行Cordova无法正常工作 - Using Automator to copy files, execute Cordova not working 如何将 Shell 脚本中的几个变量传递给 Automator 中的 AppleScript? - How to pass several variables from Shell Script to AppleScript in Automator? 将操作分配给Automator中的变量以在Shell脚本中使用 - Assign action to variable in Automator for use in Shell Script 如何对几个文件使用unix / shell paste命令 - How to use the unix/shell paste command for several files Sox-使用Shell脚本的Automator Folder Action批量标准化音频文件 - Sox - Automator Folder Action with Shell Script to batch normalise audio files Automator Action Shell脚本可压缩多个文件/文件夹(包含空格) - Automator action shell script to tar multiple files/folders (containing spaces)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM