Created
May 31, 2017 10:23
-
-
Save Cojad/b6082c8349f44ccdec905122ebdb0475 to your computer and use it in GitHub Desktop.
轉換影片格式到Telegram GIF的無聲 h264編碼的.mp4格式的Droplet AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 改編自 AppleScript範例 Recursive File Processing Droplet.app | |
-- 存檔時請存成 .app 格式 | |
-- 支援輸入的副檔名請修改 line 25: property extension_list | |
-- 請記得修改 line 117: ffmpeg執行檔的路徑, 本script需要依賴ffmpeg來完成轉換 | |
-- 本Script支援 單檔案/多檔案 但不支援資料夾遞迴處理, 如果要支援僅需把 line 81註解, line 82取消註解即可. | |
-- 如有疑問請使用 Telegram 聯繫 https://tg.me/Cojad aka @Cojad 柯姊 | |
(* | |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. | |
In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software ( the "Apple Software" ), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and / or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. | |
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. | |
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
Copyright ( C ) 2011 Apple Inc. All Rights Reserved. | |
*) | |
(* INSTRUCTIONS | |
This droplet is designed to process one or more files, or folders containing files, whose icons are dragged onto the droplet icon. | |
The droplet processes recursively, and will examine the contents of every dragged-on folder, and every sub-folder within those folders, to find and process any files who kind matches the indicated types. | |
You can set the droplet to process only files of a specific type, such as images, by adding the appropriate data types, name extensions, and type IDs to the values of the properties listed at the top of this script. | |
Place your script code for processing the found files, within the process_file() sub-routine at the bottom of this script. | |
*) | |
(* TO FILTER FOR SPECIFIC FILES, ENTER THE APPROPRIATE DATA IN THE FOLLOWING LISTS: *) | |
property type_list : {} -- e.g.: {"PICT", "JPEG", "TIFF", "GIFf"} | |
property extension_list : {"mov", "mp4"} -- e.g.: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"} | |
property typeIDs_list : {} -- e.g.: {"public.jpeg", "public.tiff", "public.png"} | |
(* IMAGE FILTERING *) | |
(* | |
-- QuickTime supported image formats | |
property type_list : {"JPEG", "TIFF", "PNGf", "8BPS", "BMPf", "GIFf", "PDF ", "PICT"} | |
property extension_list : {"jpg", "jpeg", "tif", "tiff", "png", "psd", "bmp", "gif", "jp2", "pdf", "pict", "pct", "sgi", "tga"} | |
property typeIDs_list : {"public.jpeg", "public.tiff", "public.png", "com.adobe.photoshop-image", "com.microsoft.bmp", "com.compuserve.gif", "public.jpeg-2000", "com.adobe.pdf", "com.apple.pict", "com.sgi.sgi-image", "com.truevision.tga-image"} | |
*) | |
(* MOVIE FILTERING *) | |
(* | |
-- iDVD supported movie formats | |
property type_list : {"dvc!", "MooV", "M4V ", "mpg4"} | |
property extension_list : {"mov", "mp4", "dv", "m4v","mpg"} | |
property typeIDs_list : {"public.mpeg-4", "com.apple.quicktime-movie"} | |
*) | |
-- This droplet processes files dropped onto the applet | |
on open these_items | |
repeat with i from 1 to the count of these_items | |
set this_item to item i of these_items | |
set the item_info to info for this_item | |
if folder of the item_info is true then | |
process_folder(this_item) | |
else | |
try | |
set this_extension to the name extension of item_info | |
on error | |
set this_extension to "" | |
end try | |
try | |
set this_filetype to the file type of item_info | |
on error | |
set this_filetype to "" | |
end try | |
try | |
set this_typeID to the type identifier of item_info | |
on error | |
set this_typeID to "" | |
end try | |
if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then | |
process_file(this_item) | |
end if | |
end if | |
end repeat | |
end open | |
-- this sub-routine processes folders | |
on process_folder(this_folder) | |
set these_items to list folder this_folder without invisibles | |
repeat with i from 1 to the count of these_items | |
set this_item to alias ((this_folder as Unicode text) & (item i of these_items)) | |
set the item_info to info for this_item | |
if folder of the item_info is true then | |
display alert "不支援處理資料夾" message "請拖曳檔案, 不支援拖曳資料夾." as warning buttons {"結束"} cancel button "結束" | |
-- process_folder(this_item) | |
else | |
try | |
set this_extension to the name extension of item_info | |
on error | |
set this_extension to "" | |
end try | |
try | |
set this_filetype to the file type of item_info | |
on error | |
set this_filetype to "" | |
end try | |
try | |
set this_typeID to the type identifier of item_info | |
on error | |
set this_typeID to "" | |
end try | |
if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then | |
process_file(this_item) | |
end if | |
end if | |
end repeat | |
end process_folder | |
-- this sub-routine processes files | |
on process_file(this_item) | |
-- NOTE that during execution, the variable this_item contains a file reference in alias format to the item passed into this sub-routine | |
-- FILE PROCESSING STATEMENTS GO HERE | |
set the item_info to info for this_item | |
set this_extension to the name extension of item_info | |
set this_filename to the name of item_info | |
set this_path to the POSIX path of this_item | |
set this_shortname to text 1 thru -((count this_extension) + 2) of this_filename -- the name part | |
set this_newname to text 1 thru -((count this_extension) + 2) of this_path & ".mp4" | |
do shell script "/opt/local/bin/ffmpeg -hide_banner -loglevel panic -i " & this_path & " -an -y " & this_newname -- 請自己替換為自己的ffmpeg路徑 | |
end process_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment