Archiv der Kategorie: AppleScript

AppleScript: Ordner selektieren und an Terminal übergeben

Ausgangspunkt:

In verschiedenen Ordnern liegen MP4 Files. Das AppleScript soll einen Dialog öffnen in dem man die Ordner auswählen kann, ist nur ein Ordner ausgewählt wird geprüft ob sich ein MP4 File in diesem Ordner befindet, wenn ja wird gewarnt dass nur ein Ordner ausgewählt wurde, ist kein MP4 File vorhanden wird darauf hingewiesen und ein neuer Dialog wird geöffnet.

Sind mehrere Ordner ausgewählt werden diese an den Terminal geschickt. Der Terminal führt ein Shell Script aus, welches im AppleScript Verzeichnis (*.app/Contents/Resources/Scripts/) liegt. Das Shell Script soll dann die Ordner weiterverarbeiten.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
set muxer to POSIX path of (path to resource "mxf-muxer" in directory "Scripts")
set foldercount to 0
 
tell application "Finder"
    set FolderPath to (choose folder with prompt "Pick the folders containing the files to process:" with multiple selections allowed)
    
    set foldercount to count FolderPath
    
    if (foldercount = 1) then
        set inPath to POSIX path of FolderPath as text
        set Foldername to name of folder FolderPath as text
        
        set infile to "no"
        tell application "Finder" to if exists inPath & Foldername & ".MP4" as POSIX file then set infile to "yes"
        
        if (infile = "no") then
            display dialog ("There is no file: \"" & inPath & Foldername & ".MP4" as text) & "\". Please select (multiple) folders which contains MP4 files!" buttons {"Cancel", "Select Folders"} default button "Select Folders"
            
            if button returned of result = "Select Folders" then
                set FolderPath to (choose folder with prompt "Pick the folders containing the files to process:" with multiple selections allowed)
            else
                return
            end if
        else
            display dialog "You have only select one folder, are you sure that you only want to process one file?" buttons {"Select Folders", "Continue"} default button "Continue"
            
            if button returned of result = "Select Folders" then
                set FolderPath to (choose folder with prompt "Pick the folders containing the files to process:" with multiple selections allowed)
            end if
        end if
    end if
    
    set filesString to ""
    repeat with file_ in FolderPath
        set filesString to filesString & " " & quoted form of (POSIX path of file_)
    end repeat
    
    tell application "Terminal"
        activate
        do script quoted form of muxer & filesString
    end tell
end tell

 

OSX Dateien und Ordner sichtbar/unsichtbar machen

Ein kleines Script mit dem versteckte Dateien in OSX sichtbar bzw. unsichtbar machen kann.

Script mit der Endung .command abspeichern, im Terminal ausführbar machen mit: chmod +x scriptname.command

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
 
stat=`defaults read com.apple.finder AppleShowAllFiles`
 
if [ "$stat" == "NO" ]; then
  defaults write com.apple.finder AppleShowAllFiles YES
  killall Finder /System/Library/CoreServices/Finder.app
 
else
  defaults write com.apple.finder AppleShowAllFiles NO
  killall Finder /System/Library/CoreServices/Finder.app
fi

AppleScript mp4 Compression

Ein AppleScript mit dem man mehrere Files gleichzeitig in mp4 umwandeln kann. ffmpeg für Mac wird benötigt.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
set filecount to 0
on open filelist
	set filecount to count filelist
 
	if (filecount = 2) then
		set the_array to {}
		repeat with i in filelist
			set filename to do shell script ¬
				"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
			set end of the_array to filename
		end repeat
 
		set firstfile to item 1 of the_array
		set secondfile to item 2 of the_array
 
		set revChar to reverse of (characters of firstfile) as string
		set x to (offset of "." in revChar) + 1
		set outname to text 1 thru -x of firstfile
		set ext to text -4 thru -1 of firstfile
 
		if (ext = ".m2v" or ext = ".ac3") then
			tell application "Terminal"
				activate
				do script "/Applications/ffmpeg -filter:v yadif=0:0:0 -i " & firstfile & " -i " & secondfile & " -pix_fmt yuv420p -vcodec libx264 -crf 23 -preset slow -s 768x432 -sws_flags lanczos -acodec aac -strict experimental -ab 128k -threads 0 -y " & outname & "_x264.mp4"
			end tell
		end if
 
	else if (filecount = 1 or filecount > 2) then
 
		set the_array to {}
		repeat with i in filelist
 
			set filename to do shell script ¬
				"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
			set end of the_array to filename & " "
		end repeat
		tell application "Terminal"
			activate
			do script "for j in " & the_array & "; do /Applications/ffmpeg -filter:v yadif=0:0:0 -i \"$j\" -pix_fmt yuv420p -vcodec libx264 -crf 23 -preset slow -s 768x432 -sws_flags lanczos -acodec aac -strict experimental -ab 128k -threads 0 -y \"${j%.*}\"_x264.mp4; done"
		end tell
	end if
end open
 
if filecount < 1 then
	display dialog "Please Drag and Drop one Video Files or one Video and one Audio File for Compression in MP4 x264 on it!"
	return
end if

AppleScript Time- Segment aus Video extrahieren und verarbeiten

Ein AppleScrit mit dem man ein Segment aus einem Videofile in mp4 und mp3 komprimiert und ein Frame extrahiert. das Script muss im AppleScript Editor als Programm abgespeichert werden. Anschließend können die Videofiles per Drag&Drop drauf gezogen werden. Es muss dann nur noch die Anfangszeit und die Endzeit in Form von 00:00:00.00 angegeben werden.

Hat man kein File, oder mehr als ein File ausgewählt wird eine Warnmeldung ausgegeben.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
set filecount to 0
on open infile
	set filecount to count infile
	if (filecount > 1) then
		display dialog "Please select only one file!"
		return
	end if
	set filename to do shell script ¬
		"perl -e \"print quotemeta ('" & POSIX path of infile & "');\""
	set revChar to reverse of (characters of filename) as string
	set x to (offset of "." in revChar) + 1
	set outname to text 1 thru -x of filename
 
	set StartFrame to text returned of (display dialog "Start Time:" with icon note default answer "00:15:00.24" buttons {"Cancel", "OK"} default button {"OK"})
	set EndTime to text returned of (display dialog "End Time:" with icon note default answer "01:00:00.24" buttons {"Cancel", "OK"} default button {"OK"})
	set ExtractFrame to text returned of (display dialog "Enter ExtractFrame:" with icon note default answer "00:00:30.10" buttons {"Cancel", "OK"} default button {"OK"})
 
	set std1 to text 1 thru 2 of StartFrame
	set min1 to text 4 thru 5 of StartFrame
	set sec1 to text 7 thru 8 of StartFrame
	set fps1 to text 10 thru 11 of StartFrame
 
	set stdtoframe to std1 * 60 * 60 * 25
	set mintoframe to min1 * 60 * 25
	set sectoframe to sec1 * 25
 
	set framenum to stdtoframe + mintoframe + sectoframe + fps1
 
	set std2 to text 1 thru 2 of EndTime
	set min2 to text 4 thru 5 of EndTime
	set sec2 to text 7 thru 8 of EndTime
	set fps2 to text 10 thru 11 of EndTime
 
	set stdtoframe2 to std2 * 60 * 60 * 25
	set mintoframe2 to min2 * 60 * 25
	set sectoframe2 to sec2 * 25
 
	set framenum2 to stdtoframe2 + mintoframe2 + sectoframe2 + fps2
 
	set FrameRange to framenum2 - framenum
 
	set AppleScript's text item delimiters to ","
 
	set endstd to FrameRange / 25 / 60 / 60 as string
	set endstd to text item 1 of endstd
 
	set endmin to FrameRange / 25 / 60 - endstd * 60 as string
	set endmin to text item 1 of endmin
 
	set endsec to FrameRange / 25 - endstd * 3600 - endmin * 60 as string
	set endsec to text item 1 of endsec
 
	set endfps to round (FrameRange / 25 - endstd * 3600 - endmin * 60 - endsec) * 25
 
	set timerange to endstd & ":" & endmin & ":" & endsec & "." & endfps
 
	tell application "Terminal"
		activate
		do script "/Applications/ffmpeg -ss " & StartFrame & " -t " & timerange & " -filter:v yadif=0:0:0 -i " & filename & " -pix_fmt yuv420p -vcodec libx264 -crf 23 -preset slower -s 384x216 -sws_flags lanczos -acodec aac -strict experimental -ac 1 -ar 44100 -ab 128k -threads 0 -y " & outname & ".mp4; /Applications/ffmpeg -ss " & StartFrame & " -t " & timerange & " -i " & filename & " -vn -acodec libmp3lame -ac 1 -ar 44100 -ab 64k -y " & outname & ".mp3; /Applications/ffmpeg -ss " & ExtractFrame & " -filter:v yadif=0:0:0 -i " & filename & " -frames 1 -s 500x280 -sws_flags lanczos -pix_fmt yuvj420p -sameq -y " & outname & "_" & ExtractFrame & ".jpg; exit"
	end tell
 
end open
 
if filecount < 1 then
	display dialog "Please Drag and Drop Video File for Video / Audio Compression and Frame- Extraction for Website on it!"
	return
end if