2014-09-18T19:12:45+09:00

iTunes を起動して、iPhone/iPod の同期を開始する AppleScript

表題の通り、「iTunes を起動してiPhone/iPod の同期を開始する AppleScript」を紹介します。

もしかして、皆さん、iPhone を Mac に接続したら、自動的に同期が開始するような設定にしています?僕は、勝手に同期が開始するようにはしていません。だって、充電の為だけに Mac に接続する事もあるから、勝手に同期を開始されるとうっとうしいからね。

でも、同期をしたいときは、iTunes を立ち上げてiPhone を選択して同期ボタンを押すという手順を踏まずに一発のアクションで終わらせたい。という訳で、AppleScript を書いてみました。

ところどころで delay が入っているけど、delay の時間はご自分の環境にあわせて適当に調整してね。

on run
try
main()
on error msg number errno
if errno is not -128 then
activate
display alert msg message "Error Number : " & errno
end if
end try
end run

on main()
set new_launch to false
if application "iTunes" is not running then
tell application "iTunes"
activate
end tell
set new_launch to true
end if
if new_launch then
delay 10
end if

set a_source to missing value
repeat 10 times
try
tell application "iTunes"
set a_source to some source whose kind is iPod
end tell
exit repeat
on error
delay 2
end try
end repeat

if a_source is not missing value then
tell application "iTunes"
tell a_source
update
end tell
end tell
end if
end main