Maid 提供了一些辅助方法来帮助解决这个问题。让我们将它们单独拼凑起来。
# Find all files in your Downloads
dir('~/Downloads/*')
# Find **any kind of audio files** in your Downloads
where_content_type(dir('~/Downloads/*'), 'audio')
# Copy these specific MP3 files in Downloads to a specific iTunes folder
copy(['~/Downloads/song_1.mp3', '~/Downloads/song_2.mp3'],
'~/Music/iTunes/iTunes Media/Automatically Add to iTunes/')
# Copy any MP3 files in Downloads to a specific iTunes folder
copy(dir('~/Downloads/*.mp3'),
'~/Music/iTunes/iTunes Media/Automatically Add to iTunes/')
我们可以将这些部分放在一起以实现完整目的,即将音频文件复制到“自动添加到 iTunes”文件夹中。
Maid.rules do
rule 'copy audio files to the "Automatically Add to iTunes" folder' do
copy(where_content_type(dir('~/Downloads/*'), 'audio'),
'~/Music/iTunes/iTunes Media/Automatically Add to iTunes/')
end
end
如果您愿意,可以使用变量对其进行分解——毕竟它是 Ruby。
Maid.rules do
rule 'copy audio files to the "Automatically Add to iTunes" folder' do
files_in_downloads = dir('~/Downloads/*')
audio_files_in_downloads = where_content_type(files_in_downloads, 'audio')
automatically_add_to_itunes_folder = '~/Music/iTunes/iTunes Media/Automatically Add to iTunes/'
copy(audio_files_in_downloads, automatically_add_to_itunes_folder)
end
end
我希望这有帮助!