Bluetooth

blueutil

1:ダウンロード
2:xcodeprojを開く
3:readyをまってビルド
4:バイナリーを取り出す



1:ダウンロード
20240909031513_1162x742
https://github.com/toy/blueutil


2:xcodeprojを開く
20240909024433_1366x692


3:readyをまってビルド
20240909025127_2040x718


4:バイナリーを取り出す
20240909025207_1466x834
 

|

[Bluetooth] PacketLogger(Bluetooth用ログツール)

20240518025826944x344
ダウンロードはデベロッパーサイトから
https://developer.apple.com/download/all/?q=PacketLogger
AppleScript
あくまでも参考にしてください

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

サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#https://developer.apple.com/download/all/?q=PacketLogger
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013try
014  tell application id "com.apple.PacketLogger"
015    activate
016  end tell
017on error
018  tell application "Finder"
019    open location "https://developer.apple.com/download/all/?q=PacketLogger"
020  end tell
021  return "パケットロガーをインストールしてください"
022end try
023
024
025set appFileManager to refMe's NSFileManager's defaultManager()
026set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
027set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
028set ocidSaveDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Logs/Apple/BluetoothReporter")
029set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
030ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
031set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
032if (item 1 of listDone) is true then
033  log "正常処理"
034else if (item 2 of listDone) ≠ (missing value) then
035  log (item 2 of listDone)'s code() as text
036  log (item 2 of listDone)'s localizedDescription() as text
037  return "フォルダ作成 エラーしました"
038end if
039
040set strDate to doGetDateNo("yyyyMMdd") as text
041set strSaveFileName to (strDate & "-BluetoothReporter.pklg")
042set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
043set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
044#
045try
046  set strCommandText to ("/usr/bin/sudo /System/Library/Frameworks/IOBluetooth.framework/Resources/BluetoothReporter --dumpPacketLog \"" & strSaveFilePath & "\"") as text
047  do shell script strCommandText
048on error
049  return "コマンドでエラーしました"
050end try
051#
052set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
053tell application "Finder"
054  open file aliasFilePath
055end tell
056return
057
058
059##############################
060### 今の日付日間 テキスト
061##############################
062to doGetDateNo(argDateFormat)
063  ####日付情報の取得
064  set ocidDate to current application's NSDate's |date|()
065  ###日付のフォーマットを定義
066  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
067  ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
068  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
069  ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
070  ocidNSDateFormatter's setDateFormat:(argDateFormat)
071  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
072  set strDateAndTime to ocidDateAndTime as text
073  return strDateAndTime
074end doGetDateNo
075
076
AppleScriptで生成しました

bash
あくまでも参考にしてください

サンプルソース(参考)
行番号ソース
001#! /bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003#
004SCRIPT_PATH="${BASH_SOURCE[0]}"
005/bin/echo "実行ファイル \"$SCRIPT_PATH\""
006STR_DATE=$(/bin/date +"%Y%m%d_%H%M%S")
007STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
008/bin/echo "STAT_USR(console): $STAT_USR"
009########################################
010##保存先
011STR_MKDIR_PATH="/Users/${STAT_USR}/Library/Logs/Apple/BluetoothReporter"
012/bin/mkdir -p "$STR_MKDIR_PATH"
013/usr/sbin/chown "$STAT_USR" "$STR_MKDIR_PATH"
014/bin/chmod 700 "$STR_MKDIR_PATH"
015##実行
016/usr/bin/sudo /System/Library/Frameworks/IOBluetooth.framework/Resources/BluetoothReporter --dumpPacketLog "${STR_MKDIR_PATH}/${STR_DATE}_BluetoothReporter.pklg"
017##開く
018open -b com.apple.PacketLogger "${STR_MKDIR_PATH}/${STR_DATE}_BluetoothReporter.pklg"
019
020exit 0
AppleScriptで生成しました

|

AirDropを開く


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

#!/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 framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application

set strBundleID to "com.apple.finder.Open-AirDrop" as text

set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
if ocidAppBundle ≠ (missing value) then
  set ocidAppPathURL to ocidAppBundle's bundleURL()
else if ocidAppBundle = (missing value) then
  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
end if
if ocidAppPathURL = (missing value) then
  tell application "Finder"
    try
      set aliasAppApth to (application file id strBundleID) as alias
    on error
return "アプリケーションが見つかりませんでした"
    end try
  end tell
  set strAppPath to POSIX path of aliasAppApth as text
  set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
  set strAppPath to strAppPathStr's stringByStandardizingPath()
  set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
end if

set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
(appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value))


|

[Bluetooth]スクリプトメニュー用 Bluetooth便利セット(更新)

blueutilのバージョンが2.9.1になった

ダウンロード - bluetooth.zip



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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# 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 appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()


########################
####保存先ディレクトリ
########################
set ocidLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserPathURL to ocidLibraryPathArray's objectAtIndex:0
set ocidSaveDirPathURL to ocidUserPathURL's URLByAppendingPathComponent:"Scripts/Bluetooth" isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
set listResults to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)


########################
#### ファイルダウンロード
########################
###起動時に削除される項目
set ocidTempDirPathURL to appFileManager's temporaryDirectory()
set ocidCleanupAtStartupURL to ocidTempDirPathURL's URLByAppendingPathComponent:"Cleanup At Startup"
####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
appFileManager's createDirectoryAtURL:ocidCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)

set strZipFileURL to "https://quicktimer.cocolog-nifty.com/icefloe/files/bluetooth.zip"
set ocidZipFilePath to (refMe's NSString's stringWithString:strZipFileURL)
set ocidZipFilePathURL to refMe's NSURL's alloc()'s initWithString:ocidZipFilePath

set ocidZipData to refMe's NSData's dataWithContentsOfURL:ocidZipFilePathURL

set ocidSaveZipFilePathURL to ocidCleanupAtStartupURL's URLByAppendingPathComponent:"bluetooth.zip" isDirectory:false
set boolResults to ocidZipData's writeToURL:ocidSaveZipFilePathURL atomically:true

if boolResults is false then
return "ダウンロードに失敗しました"
end if

########################
#### 解凍
########################
set strZipFilePathURL to ocidSaveZipFilePathURL's |path|() as text
set strSaveDirPathURL to (ocidSaveDirPathURL's URLByDeletingLastPathComponent())'s |path|() as text
log strZipFilePathURL
log strSaveDirPathURL
try
  set theComandText to ("/usr/bin/ditto -xk \"" & strZipFilePathURL & "\"   \"" & strSaveDirPathURL & "\"") as text
  do shell script theComandText
end try

#############################
###スクリプトメニューを有効にする
#############################
tell application id "com.apple.ScriptMenuApp"
  launch
  activate
end tell
#############################
###設定
#############################

do shell script "/usr/bin/defaults write com.apple.ScriptMenuApp \"NSStatusItem Visible com.apple.scriptmenu\" -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu PutAppScriptsFirst -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ScriptMenuEnabled -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ShowLibraryScripts -bool true"

do shell script "/usr/bin/defaults read com.apple.scriptmenu"
do shell script "/usr/bin/defaults read com.apple.ScriptMenuApp"
delay 1
#############################
###CFPreferencesを再起動
#############################
#####CFPreferencesを再起動
set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
delay 1
#############################
###関連エイリアス生成
#############################
set strOrgFilePath to "/System/Applications/Utilities/Bluetooth File Exchange.app"
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
##
set ocidDistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:"Bluetooth File Exchange.app" isDirectory:true
##
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidDistPathURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))


set strOrgFilePath to "/System/Library/CoreServices/BluetoothSetupAssistant.app"
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
##
set ocidDistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:"BluetoothSetupAssistant.app" isDirectory:true
##
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidDistPathURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))


set strOrgFilePath to "/System/Library/CoreServices/Paired Devices.app"
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
##
set ocidDistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:"Paired Devices.app" isDirectory:true
##
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidDistPathURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))



#############################
###Finderでフォルダを開く
#############################
appShardWorkspace's openURL:ocidSaveDirPathURL


return "処理終了"


|

[Bluetooth]AirDropを停止する


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

#!/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 scripting additions

property refMe : a reference to current application

###今の設定
set strCommandText to ("/usr/bin/defaults read com.apple.NetworkBrowser DisableAirDrop") as text
set intResults to (do shell script strCommandText) as integer

if intResults = 0 then
  set strMes to "AirDropが有効です 無効にします"
  set listButtons to {"AirDrop無効にします", "AirDrop有効にします", "キャンセル"}
else
  set strMes to "AirDropが無効です 有効にします"
  set listButtons to {"AirDrop有効にします", "AirDrop無効にします", "キャンセル"}
end if
#####ダイアログ
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if

set aliasIconPath to POSIX file "/System/Library/CoreServices/Finder.app/Contents/Applications/AirDrop.app/Contents/Resources/OpenAirDropAppIcon.icns" as alias
set strDefaultAnswer to strMes as text
try
  set recordResponse to (display dialog strMes with title "選んでください" buttons listButtons default button (item 1 of listButtons) cancel button (item 3 of listButtons) with icon aliasIconPath giving up after 20 without hidden answer)
on error
  log "エラーしました"
return "エラーしました"
end try
if true is equal to (gave up of recordResponse) then
return "時間切れですやりなおしてください"
end if
if "AirDrop無効にします" is equal to (button returned of recordResponse) then
  set boolAirDrop to true as boolean
else if "AirDrop有効にします" is equal to (button returned of recordResponse) then
  set boolAirDrop to false as boolean
else
  log "キャンセルしました"
return "キャンセルしました"
end if

###コマンド実行
if boolAirDrop = true then
  log "AirDropが有効です"
  set strCommandText to ("/usr/bin/defaults write com.apple.NetworkBrowser DisableAirDrop -bool true") as text
  set intResults to (do shell script strCommandText) as integer
  log "AirDropを無効に切り替えました"
else
  log "AirDropが無効です"
  set strCommandText to ("/usr/bin/defaults write com.apple.NetworkBrowser DisableAirDrop -bool false") as text
  set intResults to (do shell script strCommandText) as integer
  log "AirDropを有効に切り替えました"
end if


###CFPreferencesを再起動
set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
###Finder再起動
set strCommandText to "/usr/bin/killall Finder" as text
do shell script strCommandText

|

Bluetooth スクリプトメニュー用

ダウンロード - bluetooth.zip




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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# 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 appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()


########################
####保存先ディレクトリ
########################
set ocidLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserPathURL to ocidLibraryPathArray's objectAtIndex:0
set ocidSaveDirPathURL to ocidUserPathURL's URLByAppendingPathComponent:"Scripts/Bluetooth" isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
set listResults to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)


########################
#### ファイルダウンロード
########################
###起動時に削除される項目
set ocidTempDirPathURL to appFileManager's temporaryDirectory()
set ocidCleanupAtStartupURL to ocidTempDirPathURL's URLByAppendingPathComponent:"Cleanup At Startup"
####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
appFileManager's createDirectoryAtURL:ocidCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)

set strZipFileURL to "https://quicktimer.cocolog-nifty.com/icefloe/files/bluetooth.zip"
set ocidZipFilePath to (refMe's NSString's stringWithString:strZipFileURL)
set ocidZipFilePathURL to refMe's NSURL's alloc()'s initWithString:ocidZipFilePath

set ocidZipData to refMe's NSData's dataWithContentsOfURL:ocidZipFilePathURL

set ocidSaveZipFilePathURL to ocidCleanupAtStartupURL's URLByAppendingPathComponent:"bluetooth.zip" isDirectory:false
set boolResults to ocidZipData's writeToURL:ocidSaveZipFilePathURL atomically:true

if boolResults is false then
  return "ダウンロードに失敗しました"
end if

########################
#### 解凍
########################
set strZipFilePathURL to ocidSaveZipFilePathURL's |path|() as text
set strSaveDirPathURL to (ocidSaveDirPathURL's URLByDeletingLastPathComponent())'s |path|() as text
log strZipFilePathURL
log strSaveDirPathURL
try
  set theComandText to ("/usr/bin/ditto -xk  \"" & strZipFilePathURL & "\"   \"" & strSaveDirPathURL & "\"") as text
  do shell script theComandText
end try

#############################
###スクリプトメニューを有効にする
#############################
tell application id "com.apple.ScriptMenuApp"
  launch
  activate
end tell
#############################
###設定
#############################

do shell script "/usr/bin/defaults write com.apple.ScriptMenuApp \"NSStatusItem Visible com.apple.scriptmenu\"  -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu PutAppScriptsFirst -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ScriptMenuEnabled -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ShowLibraryScripts -bool true"

do shell script "/usr/bin/defaults read com.apple.scriptmenu"
do shell script "/usr/bin/defaults read com.apple.ScriptMenuApp"
delay 1
#############################
###CFPreferencesを再起動
#############################
#####CFPreferencesを再起動
set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
delay 1
#############################
###関連エイリアス生成
#############################
set strOrgFilePath to "/System/Applications/Utilities/Bluetooth File Exchange.app"
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
##
set ocidDistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:"Bluetooth File Exchange.app" isDirectory:true
##
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidDistPathURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))


set strOrgFilePath to "/System/Library/CoreServices/BluetoothSetupAssistant.app"
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
##
set ocidDistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:"BluetoothSetupAssistant.app" isDirectory:true
##
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidDistPathURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))


set strOrgFilePath to "/System/Library/CoreServices/Paired Devices.app"
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
##
set ocidDistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:"Paired Devices.app" isDirectory:true
##
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidDistPathURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))



#############################
###Finderでフォルダを開く
#############################
appShardWorkspace's openURL:ocidSaveDirPathURL


return "処理終了"

|

システム設定 パネルを開く アンカー指定

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#        com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

###起動
tell application id "com.apple.systempreferences"
  launch
end tell

###起動待ち
tell application id "com.apple.systempreferences"
  ###起動確認 最大10秒
  repeat 10 times
    activate
    set boolFrontMost to frontmost as boolean
    if boolFrontMost is true then
      exit repeat
    else
      delay 1
    end if
  end repeat
end tell
###パネルを開く アンカー指定
tell application id "com.apple.systempreferences"
  launch
  activate
  reveal anchor "Main" of pane id "com.apple.BluetoothSettings"
end tell
###名前を取得して
tell application id "com.apple.systempreferences"
  launch
  activate
  tell front window
    set strWindowName to name as text
  end tell
end tell
####開けていなかったらコマンドで開く
if strWindowName is not "Bluetooth" then
  set theCommandText to ("open \"x-apple.systempreferences:com.apple.preferences.Bluetooth?Main\"") as text
  do shell script theCommandText
else
  return "処理終了"
end if



|

[システム設定]Bluetooth com.apple.BluetoothSettings(macOS13)

#!/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 scripting additions




property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL


set aliasScriptsFolder to path to scripts folder from user domain as alias
tell application "Finder"
set boolFolderChk to (exists of (folder "Bluetooth" of folder aliasScriptsFolder)) as boolean
if (boolFolderChk is false) then
make new folder at aliasScriptsFolder with properties {name:"Bluetooth"}
end if
set aliasColorFolder to folder "Bluetooth" of folder aliasScriptsFolder as «class furl»
end tell

set aliasOrigFilePath to (POSIX file "/System/Applications/Utilities/Bluetooth File Exchange.app") as alias

tell application "Finder"
set boolFolderChk to (exists of (file "Bluetoothファイル交換.app" of folder "Bluetooth" of folder aliasScriptsFolder)) as boolean
if (boolFolderChk is false) then
make alias at aliasColorFolder to aliasOrigFilePath
end if
end tell

set aliasOrigFilePath to (POSIX file "/System/Library/CoreServices/BluetoothSetupAssistant.app") as alias

tell application "Finder"
set boolFolderChk to (exists of (file "Bluetooth設定アシスタント.app" of folder "Bluetooth" of folder aliasScriptsFolder)) as boolean
if (boolFolderChk is false) then
make alias at aliasColorFolder to aliasOrigFilePath
end if
end tell


set aliasOrigFilePath to (POSIX file "//System/Library/CoreServices/Paired Devices.app") as alias

tell application "Finder"
set boolFolderChk to (exists of (file "ペアリング済みのデバイス.app" of folder "Bluetooth" of folder aliasScriptsFolder)) as boolean
if (boolFolderChk is false) then
make alias at aliasColorFolder to aliasOrigFilePath
end if
end tell


set ocidWorkspace to refMe's NSWorkspace's sharedWorkspace()

###
set ocidSystemPreferencesURL to refNSURL's URLWithString:"x-apple.systempreferences:com.apple.BluetoothSettings"



###アンカーの指定方法がわからない
ocidWorkspace's openURL:ocidSystemPreferencesURL

|

[Bluetooth]/blueutil

https://github.com/toy/blueutil
XcodeでBuildしても良いですし
makeもできます。

sh-3.2$ ./blueutil

Power: 1

Discoverable: 0

sh-3.2$ 

sh-3.2$ ./blueutil -H

blueutil: invalid option -- H

blueutil v2.9.0


Usage:

  blueutil [options]


Without options outputs current state


    -p, --power               output power state as 1 or 0

    -p, --power STATE         set power state

    -d, --discoverable        output discoverable state as 1 or 0

    -d, --discoverable STATE  set discoverable state


        --favourites, --favorites

                              list favourite devices

        --inquiry [T]         inquiry devices in range, 10 seconds duration by default excluding time for name updates

        --paired              list paired devices

        --recent [N]          list recently used devices, 10 by default, 0 to list all

        --connected           list connected devices


        --info ID             show information about device

        --is-connected ID     connected state of device as 1 or 0

        --connect ID          create a connection to device

        --disconnect ID       close the connection to device

        --pair ID [PIN]       pair with device, optional PIN of up to 16 characters will be used instead of interactive input if requested in specific pair mode

        --unpair ID           EXPERIMENTAL unpair the device

        --add-favourite ID, --add-favorite ID

                              add to favourites

        --remove-favourite ID, --remove-favorite ID

                              remove from favourites


        --format FORMAT       change output format of info and all listing commands


        --wait-connect ID [TIMEOUT]

                              EXPERIMENTAL wait for device to connect

        --wait-disconnect ID [TIMEOUT]

                              EXPERIMENTAL wait for device to disconnect

        --wait-rssi ID OP VALUE [PERIOD [TIMEOUT]]

                              EXPERIMENTAL wait for device RSSI value which is 0 for golden range, -129 if it cannot be read (e.g. device is disconnected)


    -h, --help                this help

    -v, --version             show version


STATE can be one of: 1, on, 0, off, toggle

ID can be either address in form xxxxxxxxxxxx, xx-xx-xx-xx-xx-xx or xx:xx:xx:xx:xx:xx, or name of device to search in used devices

OP can be one of: >, >=, <, <=, =, !=; or equivalents: gt, ge, lt, le, eq, ne

PERIOD is in seconds, defaults to 1

TIMEOUT is in seconds, default value 0 doesn't add timeout

FORMAT can be one of:

  default - human readable text output not intended for consumption by scripts

  new-default - human readable comma separated key-value pairs (EXPERIMENTAL, THE BEHAVIOUR MAY CHANGE)

  json - compact JSON

  json-pretty - pretty printed JSON


Due to possible problems, blueutil will refuse to run as root user (see https://github.com/toy/blueutil/issues/41).

Use environment variable BLUEUTIL_ALLOW_ROOT=1 to override (sudo BLUEUTIL_ALLOW_ROOT=1 blueutil …).


Exit codes:

   0 Success

   1 General failure

  64 Wrong usage like missing or unexpected arguments, wrong parameters

  69 Bluetooth or interface not available

  70 Internal error

  71 System error like shortage of memory

  75 Timeout error

sh-3.2$ 

sh-3.2$ 

|

[Bluetooth]Bluetoothファイル共有を停止させる

Bluetoothファイル共有を停止させる

ダウンロード - bluetoothstopfileshare.scpt.zip

#!/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 scripting additions

try
set theComandText to ("/usr/bin/defaults -currentHost write com.apple.Bluetooth PrefKeyServicesEnabled -boolean false") as text
do shell script theComandText
end try

try
set theComandText to ("/usr/bin/defaults -currentHost write com.apple.Bluetooth OBEXFileHandling -integer 2") as text
do shell script theComandText
end try

try
set theComandText to ("/usr/bin/defaults -currentHost write com.apple.Bluetooth OBEXBrowseConnectionHandling -integer 2") as text
do shell script theComandText
end try

try
set theComandText to ("/usr/bin/defaults -currentHost write com.apple.Bluetooth OBEXOtherDataDisposition -integer 0") as text
do shell script theComandText
end try
#######################
try
set theComandText to ("/usr/bin/defaults write com.apple.BluetoothFileExchange OBEXFTPRootFolderLocation -string \"~/Public\"") as text
do shell script theComandText
end try
try
set theComandText to ("/usr/bin/defaults write com.apple.BluetoothFileExchange OBEXPIMDataSaveToLocation -string \"~/Downloads\"") as text
do shell script theComandText
end try

#######################
try
set theComandText to ("/usr/bin/defaults write com.apple.BluetoothFileExchange IOBluetoothDeviceSelectorModalDeviceTypeIndex -integer 0") as text
do shell script theComandText
end try
try
set theComandText to ("/usr/bin/defaults write com.apple.BluetoothFileExchange IOBluetoothDeviceSelectorModalDeviceCategoryIndex -integer 0") as text
do shell script theComandText
end try
try
set theComandText to ("/usr/bin/defaults write com.apple.BluetoothFileExchange StartupBehaviorKey -integer 0") as text
do shell script theComandText
end try
try
set theComandText to ("/usr/bin/defaults write com.apple.BluetoothFileExchange NSNavLastRootDirectory -string \"~/Public\"") as text
do shell script theComandText
end try
#######################
try
tell application "System Preferences" to launch

repeat
set doLaunchApp to get running of application "System Preferences"
if doLaunchApp is false then
delay 0.5
else
exit repeat
end if
end repeat

repeat
try
tell application "System Preferences"
set current pane to pane "com.apple.preferences.sharing"
set thePaneID to id of current pane
end tell
on error
delay 0.5
tell application "System Preferences"
set thePaneID to id of current pane
end tell
end try
if thePaneID is "com.apple.preferences.sharing" then
exit repeat
else
delay 0.5
end if
end repeat

--アンカーを指定する
tell application "System Preferences"
tell current pane
reveal anchor "share"
end tell
end tell
tell application "System Preferences"
tell current pane
reveal anchor "share"
end tell
activate
end tell


on error
set theCommandText to ("open \"x-apple.systempreferences:com.apple.preferences.sharing?Services_BluetoothSharing\"") as text
do shell script theCommandText

end try

|

より以前の記事一覧

その他のカテゴリー

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