Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive

タグ: Image Events

iTunes上で選択中のTrackのアートワークを指定画像に設定する

Posted on 11月 10, 2018 by Takaaki Naganoya

iTunes上で選択中のトラックに対して、指定の画像をアートワークとして指定するAppleScriptです。

1つのトラックに対して複数のアートワークが設定できる仕様になっており、そのあたりで迷うかもしれません。

選択中の1つのトラックに対してchoose fileコマンドで指定した画像をアートワークとして設定する……という程度では、ぜんぜん自動化のパワーが発揮されないので、実際にはトラック情報と対応するアートワーク画像ファイル名をNumbers上に書いておくと、それを読み取って指定フォルダ以下の画像をすべて指定トラックのアートワークに指定する、とかいうあたりが落とし所でしょうか。


▲iTunes上でアートワークのついていないトラックを選択中


▲本AppleScriptを実行して、てきとーに画像を選択


▲選択中のトラックにアートワーク画像が指定された


▲iTunes上でCommand-iで選択中のトラックの詳細情報を確認して、アートワーク画像が設定されたことを確認したところ

AppleScript名:選択中のTrackのアートワークを指定画像に設定する
set aFile to choose file of type {"public.image"}

tell application "Image Events"
  set aRaw to read aFile as image
end tell

tell application "iTunes"
  set sList to selection
  
  
repeat with i in sList
    if class of i = file track then
      set data of artwork 1 of i to aRaw
    end if
  end repeat
  
end tell

★Click Here to Open This Script 

Posted in file Image | Tagged 10.11savvy 10.12savvy Image Events iTunes | Leave a comment

指定フォルダ内のJPEGファイルのEXIFから撮影日付を取得してファイルの作成日付に反映させる v2

Posted on 5月 31, 2018 by Takaaki Naganoya

指定フォルダ内のすべてのJPEGファイルのEXIF情報から撮影日付を取得し、画像ファイルの作成日付に反映させるAppleScriptです。

写真.app(Photos.app)内で管理している大量の写真ファイルをいったんファイルに書き出して、DVD-Rにコピーして人に渡すときに、写真の作成日付が撮影日になっておらず、Finderなどのファイラー上で整理するのが大変でした。

ファイル書き出しなので仕方のないことですが、この仕様はいただけません。

かようにファイル作成日付が正しくない写真でも、EXIFに正しい撮影日付が保存されているケースが多い(ただし、完全にすべてではない)ため、EXIFの日付をAppleScriptで読み取ってファイル作成日付に反映させてみました。

写真.appなどのアプリケーションにインポートしてしまえばEXIF日付でソートされるので、あまり意味があるとも思えませんが、Finder上での写真整理のために実行してとりあえず走らせてみました。

AppleScript名:EXIFから撮影日付を取得してファイルの作成日付に反映させる v2
— Created 2018-05-30 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"

script spd
  property fList : {}
end script

set renCount to 0

set (fList of spd) to {}

set aFolder to (choose folder)

set aDate to current date

set (fList of spd) to getFilePathList(aFolder, "JPG") of me

repeat with i in (fList of spd)
  set j to contents of i
  
chkCreationDateAsExif(j) of me
  
set renCount to renCount + 1
end repeat

set bDate to current date

return {bDate – aDate, renCount}

on chkCreationDateAsExif(aFile)
  tell application "Image Events"
    launch
    
set this_image to open (aFile as alias)
    
    
try
      tell this_image
        set aVal to (value of metadata tag "creation")
      end tell
    on error
      return
    end try
    
    
close this_image
  end tell
  
  
set a to current application’s NSString’s stringWithString:aVal
  
set {aDateStr, aTimeStr} to (a’s componentsSeparatedByString:" ") as list
  
set bDateStr to repChar(aDateStr, ":", "/") of me
  
set fullDate to date (bDateStr & " " & aTimeStr)
  
  
set aDic to current application’s NSMutableDictionary’s dictionaryWithObject:fullDate forKey:(current application’s NSFileModificationDate)
  
set aFM to current application’s NSFileManager’s defaultManager()’s setAttributes:aDic ofItemAtPath:(POSIX path of aFile) |error|:(missing value)
end chkCreationDateAsExif

–文字置換
on repChar(origText as string, targChar as string, repChar as string)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to targChar
  
set tmpList to text items of origText
  
set AppleScript’s text item delimiters to repChar
  
set retText to tmpList as string
  
set AppleScript’s text item delimiters to curDelim
  
return retText
end repChar

on getFilePathList(aFol, aExt)
  set aFol to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aFol)
  
  
set aFM to current application’s NSFileManager’s defaultManager()
  
set urlArray to aFM’s contentsOfDirectoryAtURL:aFol includingPropertiesForKeys:{} options:(current application’s NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
  
set thePred to current application’s NSPredicate’s predicateWithFormat:"pathExtension == [c]%@" argumentArray:{aExt}
  
set anArray to urlArray’s filteredArrayUsingPredicate:thePred
  
return anArray as list — URLs pre-10.11, files under 10.11
end getFilePathList

★Click Here to Open This Script 

Posted in exif file Image | Tagged 10.11savvy 10.12savvy 10.13savvy Image Events | Leave a comment

電子書籍をBOOTH.pmほかで販売中!!

Tags

10.11savvy (1052) 10.12savvy (1069) 10.13savvy (1049) 10.14savvy (94) CotEditor (30) Dictionary (9) Dock (7) Finder (28) ITLibrary (13) iTunes (21) Keynote (24) Mail (9) NSArray (25) NSBezierPath (7) NSBitmapImageRep (7) NSBundle (5) NSButton (8) NSColor (13) NSCountedSet (7) NSDictionary (11) NSFileManager (10) NSImage (17) NSMutableArray (15) NSMutableDictionary (7) NSPredicate (20) NSScreen (14) NSSortDescriptor (10) NSString (35) NSURL (23) NSUUID (7) NSView (6) NSWindow (9) NSWindowController (9) NSWorkspace (6) Numbers (17) OSALanguage (5) OSAScript (7) Pages (5) QuickTime Player (8) Safari (16) Script Editor (9) Sorting (5) System Events (8) Terminal (5) TextEdit (12)

カテゴリー

  • AirDrop
  • AirPlay
  • AppleScript Application on Xcode
  • Bluetooth
  • boolean
  • Calendar
  • Clipboard
  • Color
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • geolocation
  • GUI
  • GUI Scripting
  • Icon
  • Image
  • Input Method
  • Internet
  • Keychain
  • Language
  • list
  • Locale
  • Machine Learning
  • Markdown
  • Menu
  • MIDI
  • Natural Language Processing
  • Network
  • Noification
  • Number
  • OCR
  • OSA
  • PDF
  • QR Code
  • Record
  • regexp
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • RTF
  • Sandbox
  • Screen Saver
  • search
  • shell script
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • System
  • Tag
  • Text
  • Text to Speech
  • timezone
  • URL
  • UTI
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月





メタ情報

  • 登録
  • ログイン
  • 投稿の RSS
  • コメントの RSS
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC