20260401

【applescript】coreaudiodの再起動


【applescript】coreaudiodの再起動

NOTE記事一覧ですnote.com

【スクリプトエディタで開く】 |

コアオーディオ再起動.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
004(*
005コアオーディオ再起動
006com.cocolog-nifty.quicktimer.icefloe *)
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
008use AppleScript version "2.8"
009use scripting additions
010property refMe : a reference to current application
011#OSのバージョン取得
012set recordSystemInfo to (system info) as record
013set strOsVersion to (system version of recordSystemInfo) as text
014#メジャーバージョンとマイナーバージョンを分離
015set strDelim to AppleScript's text item delimiters
016set AppleScript's text item delimiters to (".")
017set listVersion to every text item of strOsVersion
018set AppleScript's text item delimiters to strDelim
019#バージョンを数値で定義して
020set numVerMaj to (first item of listVersion) as integer
021set numVerMim to (second item of listVersion) as integer
022#OSのバージョンで処理を分岐
023if numVerMaj < 14 then
024   set strCmd to ("/usr/bin/sudo /bin/launchctl kickstart -kp system/com.apple.audio.coreaudiod") as text
025   do shell script strCmd
026   
027else if (numVerMaj = 14) and (numVerMim < 4) then
028   set strCmd to ("/usr/bin/sudo /bin/launchctl kickstart -kp system/com.apple.audio.coreaudiod") as text
029   do shell script strCmd
030else if (numVerMaj = 14) and (numVerMim < 6) then
031   set strCmd to ("/usr/bin/sudo /usr/bin/killall coreaudiod") as text
032   do shell script strCmd
033end if
034#共通処理
035delay 5
036set strCmd to ("/usr/bin/sudo /usr/bin/killall coreaudiod") as text
037do shell script strCmd
038return
AppleScriptで生成しました