AppleScript名:QuickTIme Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存 |
— Created 2018-01-20 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" –http://piyocast.com/as/archives/5123 property NSUUID : a reference to current application’s NSUUID property NSString : a reference to current application’s NSString property NSImage : a reference to current application’s NSImage property NSPasteboard : a reference to current application’s NSPasteboard property NSJPEGFileType : a reference to current application’s NSJPEGFileType property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep set the clipboard to "" –Clear Clipboard (=Pasteboard) tell application "QuickTime Player" –No Document check if (count every document) < 1 then display dialog "No Document…" with icon 2 buttons {"OK"} default button 1 return end if –Audio Movie check if natural dimensions of front document = {0, 0} then display dialog "This is an audio file" with icon 2 buttons {"OK"} default button 1 return end if end tell repeat 100 times activate application "QuickTime Player" tell application "System Events" tell process "QuickTime Player" click menu item 5 of menu 1 of menu bar item 4 of menu bar 1 –Edit > Copy end tell end tell delay 0.1 set aRes to dataIsInClipboard for JPEG picture if aRes = true then exit repeat end repeat if aRes = false then return –クリップボードの内容をNSImageに set aNSIMage to my getClipboardASImage() –保存先とファイル名を求める set targFol to POSIX path of (path to desktop) set aUUID to NSUUID’s UUID()’s UUIDString() as text set outPath to targFol & aUUID & ".jpg" set aRes to saveNSImageAtPathAsJPG(aNSIMage, outPath, 1.0) of me — クリップボードの内容をNSImageとして取り出して返す on getClipboardASImage() set theNSPasteboard to NSPasteboard’s generalPasteboard() set imageArray to theNSPasteboard’s readObjectsForClasses:({NSImage}) options:(missing value) set targImage to imageArray’s objectAtIndex:0 return targImage end getClipboardASImage –NSImageを指定パスにJPEG形式で保存、qulityNumは0.0〜1.0。1.0は無圧縮 on saveNSImageAtPathAsJPG(anImage, outPath, qulityNum as real) set imageRep to anImage’s TIFFRepresentation() set aRawimg to NSBitmapImageRep’s imageRepWithData:imageRep set pathString to NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(NSJPEGFileType) |properties|:{NSImageCompressionFactor:qulityNum}) return (myNewImageData’s writeToFile:newPath atomically:true) as boolean end saveNSImageAtPathAsJPG –http://ashplanning.blogspot.jp/2006/12/blog-post.html on dataIsInClipboard for dataType return (clipboard info for dataType) is not {} end dataIsInClipboard |
(Visited 53 times, 1 visits today)