AppleScript CD/DVD

com.apple.CD-DVD-Settings.extensionシステム設定を開く


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

###システム設定を開いて
tell application "System Settings" to launch
###起動確認10秒
repeat 10 times
  tell application "System Settings" to activate
  ###前面のアプリケーション
  tell application "System Events"
    set strAppName to (name of first application process whose frontmost is true) as text
  end tell
  ####起動確認できたら抜ける
  if strAppName is "System Settings" then
    exit repeat
  else
    ###起動に時間がかかっている場合は1秒まつ
    delay 1
  end if
end repeat

####パネルオープン確認
tell application "System Settings"
  activate
  repeat 10 times
    ####ウィンドウの名前を取得する
    set strWindowName to (name of front window) as text
    ###取得できなかったら1秒待つ
    if strWindowName is "" then
      delay 1
      ###取得できたらリピート抜ける
    else if strWindowName is "外観" then
      exit repeat
      ###すでに起動済みで外観以外を開いている場合
    else
      exit repeat
    end if
  end repeat
end tell

tell application "System Settings"
  try
reveal anchor "Main" of pane id "com.apple.CD-DVD-Settings.extension"
  on error
return "CD/DVDデバイスが接続されていないと開けません"
  end try
end tell

tell application "System Settings" to activate
####パネルオープン確認
tell application "System Settings"
  ###起動確認 最大10秒
  repeat 10 times
    activate
    ####ウィンドウの名前を取得する
    set strWindowName to (name of front window) as text
    ###取得できなかったら1秒待つ
    if strWindowName is "" then
      delay 1
      ###取得できたらリピート抜ける
    else if strWindowName is "CDとDVD" then
      exit repeat
      ###すでに起動済みで外観以外を開いている場合
    else
      delay 1
    end if
  end repeat
end tell



|

[com.apple.digihub]com.apple.digihub設定スクリプト


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


###############################################
###Plist編集

##########################################
###【1】パスURL
set strFilePath to "~/Library/Preferences/com.apple.digihub.plist"
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)

##########################################
### 【2】PLISTを可変レコードとして読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)

##########################################
### 【3】処理はここで
set ocidBlankCdDict to ocidPlistDict's objectForKey:("com.apple.digihub.blank.cd.appeared")
set ocidBlankDvdDict to ocidPlistDict's objectForKey:("com.apple.digihub.blank.dvd.appeared")
set ocidMusicCdDict to ocidPlistDict's objectForKey:("com.apple.digihub.cd.music.appeared")
set ocidPictureCdDict to ocidPlistDict's objectForKey:("com.apple.digihub.cd.music.appeared")
set ocidVideoDvdDict to ocidPlistDict's objectForKey:("com.apple.digihub.dvd.video.appeared")
(* ###Set action
1=無視
2=動作を確認
5=otherapp他のアプリケーションで開く 
6=otherscriptスクリプトを実行 
100=Finder
101=Music
102=ディスクユーティティ
*)
ocidBlankCdDict's setValue:(1) forKey:("action")
ocidBlankDvdDict's setValue:(1) forKey:("action")
ocidMusicCdDict's setValue:(1) forKey:("action")
ocidPictureCdDict's setValue:(1) forKey:("action")
ocidVideoDvdDict's setValue:(1) forKey:("action")

set ocidSetDict to refMe's NSDictionary's dictionaryWithDictionary:({|_CFURLStringType|:15, |_CFURLString|:"file:///System/Library/CoreServices/Finder.app/"})
ocidBlankCdDict's setObject:(ocidSetDict) forKey:("otherapp")
ocidBlankDvdDict's setObject:(ocidSetDict) forKey:("otherapp")
ocidMusicCdDict's setObject:(ocidSetDict) forKey:("otherapp")
ocidPictureCdDict's setObject:(ocidSetDict) forKey:("otherapp")
ocidVideoDvdDict's setObject:(ocidSetDict) forKey:("otherapp")

set ocidSetDict to refMe's NSDictionary's dictionaryWithDictionary:({|_CFURLStringType|:15, |_CFURLString|:"file:///Library/Scripts/FOOHOGE.applescript"})
ocidBlankCdDict's setObject:(ocidSetDict) forKey:("otherscript")
ocidBlankDvdDict's setObject:(ocidSetDict) forKey:("otherscript")
ocidMusicCdDict's setObject:(ocidSetDict) forKey:("otherscript")
ocidPictureCdDict's setObject:(ocidSetDict) forKey:("otherscript")
ocidVideoDvdDict's setObject:(ocidSetDict) forKey:("otherscript")


##########################################
####【4】保存 ここは上書き
set boolDone to ocidPlistDict's writeToURL:(ocidFilePathURL) atomically:true

log boolDone

return "処理終了"






|

[CD/DVD]基本

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
########################

/bin/df

/bin/dd

/usr/bin/hdiutil 

/usr/bin/drutil

/usr/sbin/diskutil

/sbin/mount

/sbin/umount 

/usr/sbin/dot_clean

/usr/sbin/fdisk

/usr/sbin/hdik

|

ISOイメージを作るDD版.scpt

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()





####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    set strDevicePath to ocidDevicePath as text
    
    set ocidCharacterSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:"/")
    set ocidVolArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
    set strDiskName to (ocidVolArray's lastObject()) as text
  end if
end repeat

####################################
####ディスクの表示名
####################################

set strMountPath to ("/Volumes/" & strDiskName) as text

tell application "Finder"
  set aliasMountPath to (POSIX file strMountPath) as alias
end tell


####################################
####ダイアログ
####################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "iso"
set strDefaultName to (strDiskName & "." & strFileExtension) as text
set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
set strSaveFilePath to (POSIX path of aliasFilePath) as text
####ドキュメントのパスをNSString
set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
####ドキュメントのパスをNSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if
set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text

####################################
#### まずアンマウント
####################################
try
  set strCommandText to ("/usr/sbin/diskutil unmount " & strDevicePath & "") as text
  log strCommandText
  do shell script strCommandText
on error
  set strCommandText to ("/usr/bin/sudo /sbin/umount " & strDevicePath & "") as text
  log strCommandText
  do shell script strCommandText with administrator privileges
end try
###5秒待つ
delay 5
####################################
#### ISOイメージ作成dd
####################################
###通常はこれだけど
set strCommandText to ("/bin/dd if=" & strDevicePath & " of=\"" & strSaveFilePath & "\"") as text
###AudioCDはこれ
set strCommandText to ("/bin/dd if=" & strDevicePath & " of=\"" & strSaveFilePath & "\" bs=2048 conv=sync,notrunc") as text
log strCommandText
do shell script strCommandText
delay 5
####################################
#### イジェクト する場合
####################################
try
  set strCommandText to ("/usr/bin/drutil eject") as text
  do shell script strCommandText
on error
  delay 1
  try
    set strCommandText to ("/usr/sbin/diskutil eject " & strDevicePath & "") as text
    do shell script strCommandText
  on error
    delay 1
    set strCommandText to ("/usr/sbin/hdiutil eject \"" & strMountPath & "\" -force") as text
    do shell script strCommandText
  end try
end try

return


####################################
#### 再度マウントする場合
####################################

set strCommandText to ("/usr/sbin/diskutil mount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText

return


|

ISOイメージを作るHDIUTIL版

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    set strDevicePath to ocidDevicePath as text
    
    set ocidCharacterSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:"/")
    set ocidVolArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
    set strDiskName to (ocidVolArray's lastObject()) as text
  end if
end repeat

####################################
####ディスクの表示名
####################################

set strMountPath to ("/Volumes/" & strDiskName) as text

tell application "Finder"
  set aliasMountPath to (POSIX file strMountPath) as alias
end tell


####################################
####ダイアログ
####################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "iso"
set strDefaultName to (strDiskName & "." & strFileExtension) as text
set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
set strSaveFilePath to (POSIX path of aliasFilePath) as text
####ドキュメントのパスをNSString
set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
####ドキュメントのパスをNSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if
set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text

####################################
#### まずアンマウント
####################################
try
  set strCommandText to ("/usr/sbin/diskutil unmount " & strDevicePath & "") as text
  log strCommandText
  do shell script strCommandText
on error
  set strCommandText to ("/usr/bin/sudo /sbin/umount " & strDevicePath & "") as text
  log strCommandText
  do shell script strCommandText with administrator privileges
end try
###5秒待つ
delay 5
####################################
#### ISOイメージ作成makehybrid
####################################
###AudioCDはこれ
set strCommandText to ("/usr/bin/hdiutil makehybrid -iso -joliet -o \"" & strSaveFilePath & "\" " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText
delay 5


return
####################################
#### イジェクト する場合
####################################
try
  set strCommandText to ("/usr/bin/drutil eject") as text
  do shell script strCommandText
on error
  try
    set strCommandText to ("/usr/sbin/diskutil eject " & strDevicePath & "") as text
    do shell script strCommandText
  on error
    set strCommandText to ("/usr/sbin/hdiutil eject \"" & strMountPath & "\" -force") as text
    do shell script strCommandText
  end try
end try

####################################
#### 再度マウントする場合
####################################

set strCommandText to ("/usr/sbin/diskutil mount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText

return


|

CD/DVDのイジェクト

アンマウントされていてデバイス名を取得出来ない場合は
drutilでイジェクトする2段がまえ

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    log boolCD
    log ocidDevicePath as text
    -->CD/DVDのデバイス名
    ##デバイス名を取得
    set ocidCDDevicePath to (ocidDevArray's lastObject())
    set ocidFilePath to ocidCDDevicePath's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
    ######アンマウントする
(appNSWorkspace's unmountAndEjectDeviceAtURL:ocidFilePathURL |error|:(reference))
  else
    ####ELSE=CD/DVDデバイスが接続されていないか?マウントされていない場合
    set strCommandText to ("/usr/bin/drutil eject") as text
    do shell script strCommandText
  end if
end repeat


|

CD/DVDのアンマウント(not eject)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    log boolCD
    set strDevicePath to ocidDevicePath as text
    
    try
set strCommandText to ("/usr/sbin/diskutil unmount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText
    on error
set strCommandText to ("/usr/bin/sudo /sbin/umount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText with administrator privileges
    end try
    
  end if
end repeat



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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    log boolCD
    set strDevicePath to ocidDevicePath as text
    
    set strCommandText to ("/usr/sbin/diskutil unmount " & strDevicePath & "") as text
    do shell script strCommandText
  end if
end repeat



|

[NSWorkspace]CD/DVDをイジェクトする

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    log boolCD
    log ocidDevicePath as text
    -->CD/DVDのデバイス名
    ##デバイス名を取得
    set ocidCDDevicePath to (ocidDevArray's lastObject())
    set ocidFilePath to ocidCDDevicePath's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
    
    ######アンマウントする
(appNSWorkspace's unmountAndEjectDeviceAtURL:ocidFilePathURL |error|:(reference))
  end if
end repeat


|

[df]CD/DVDのデバイス名を取得する

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  ##スペース指定
  set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
  set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
  ##デバイス名を取得
  set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
  ###CD/DVDデバイス用の整形表現
  set strRegPattern to "/dev/disk[0-9]+"
  ###正規表現で判定項目を作って(マッチなら)
  set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
  ###CD判定
  set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
  if boolCD is ocidTrue then
    log boolCD
    log ocidDevicePath as text
    -->CD/DVDのデバイス名
  end if
end repeat


|

[df]デバイス名取得(リムーバルメディア)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

set ocidFalse to (refMe's NSNumber's numberWithBool:false)
set ocidTrue to (refMe's NSNumber's numberWithBool:true)

####################################
####全マウントボリューム取得
####################################
##オプション
set ocidOption to (refMe's NSVolumeEnumerationProduceFileReferenceURLs)
##取得キー
set ocidKeysArray to {(refMe's NSURLNameKey), (refMe's NSURLPathKey), (refMe's NSURLVolumeIsEjectableKey), (refMe's NSURLVolumeIsRemovableKey), (refMe's NSURLVolumeIsInternalKey)}
##取得
set ocidDiskArray to appFileManager's mountedVolumeURLsIncludingResourceValuesForKeys:(ocidKeysArray) options:(ocidOption)
##ボリュームの数だけ繰返し
repeat with itemDiskArrayURL in ocidDiskArray
  ##リソースキーを取得
  set listResDict to (itemDiskArrayURL's resourceValuesForKeys:ocidKeysArray |error|:(reference))
  ##取り出し
  set ocidResourceValuesDict to item 1 of listResDict
  ##内臓判定
  set boolIsInternal to (ocidResourceValuesDict's objectForKey:(refMe's NSURLVolumeIsInternalKey))
  ###外付けを取得する
  if boolIsInternal is (ocidFalse) then
    set ocidInternalName to (ocidResourceValuesDict's objectForKey:(refMe's NSURLNameKey))
    log ocidInternalName as text
    ##リムーバブル判定 -->CD/DVDメディア か USBメモリ
    set boolIsRemovable to (ocidResourceValuesDict's objectForKey:(refMe's NSURLVolumeIsRemovableKey))
    if boolIsRemovable is (ocidTrue) then
set ocidRemovableName to (ocidResourceValuesDict's objectForKey:(refMe's NSURLNameKey))
log ocidRemovableName as text
    end if
  end if
end repeat


####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
  set strItemStringArray to itemStringArray as text
  if strItemStringArray contains (ocidRemovableName as text) then
    log strItemStringArray
    ##スペース指定
    set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
    set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
    --->指定ドライブの
    log (ocidDevArray's objectAtIndex:0) as text
  end if
end repeat







|

より以前の記事一覧

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom