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







|

より以前の記事一覧

その他のカテゴリー

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