AppleScript NetWork

今参照しているDNS情報を取得する


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

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

##コマンド実行
set strCommandText to ("/usr/sbin/scutil --dns") as text
set strResponse to (do shell script strCommandText) as text
#戻り値をテキストに
set ocidReadString to refMe's NSString's stringWithString:(strResponse)
#改行をUNIXに強制
set ocidReadText to (ocidReadString's stringByReplacingOccurrencesOfString:("\r\n") withString:("\n"))
set ocidReadText to (ocidReadText's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
#改行毎でリストにする
set ocidCharSet to (refMe's NSCharacterSet's newlineCharacterSet)
set ocidLineArray to (ocidReadText's componentsSeparatedByCharactersInSet:(ocidCharSet))
#出力用テキスト
set ocidSaveString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
#全行処理
repeat with itemArray in ocidLineArray
  #必要な情報のみ出力用テキストに入れていく
  set ocidBool to (itemArray's containsString:("search domain"))
  if ocidBool is (true) then
(ocidSaveString's appendString:(itemArray))
(ocidSaveString's appendString:("\n"))
  end if
  set ocidBool to (itemArray's containsString:("nameserver"))
  if ocidBool is (true) then
(ocidSaveString's appendString:(itemArray))
(ocidSaveString's appendString:("\n"))
  end if
end repeat
set strAns to ocidSaveString as text

###ダイアログを前面に出す
set strName to (name of current application) as text
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/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias


try
  set recordResponse to (display dialog "DNS戻り値" with title "IPアドレス" default answer strAns buttons {"クリップボードにコピー", "OK", "キャンセル"} default button "OK" cancel button "キャンセル" 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 "OK" is equal to (button returned of recordResponse) then
  set strResponse to (text returned of recordResponse) as text
else if button returned of recordResponse is "クリップボードにコピー" then
  set strText to text returned of recordResponse as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  ##結果をペーストボードにテキストで入れる
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
return strText
else
log "キャンセルしました"
return "キャンセルしました" & strText
end if






|

ネットワークスピードテスト(macOS14対応)


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

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


set strDefaultAnswer to "/usr/bin/networkQuality -v -s -I en0" as text

################################
######ダイアログ
################################
#####ダイアログを前面に
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/CoreTypes.bundle/Contents/Resources/GenericNetworkIcon.icns" as alias
try
  set recordResponse to (display dialog "コマンドオプションを入力してください\rOK押してから結果が出るまで30秒ほどかかります" with title "ネットワークスピードテスト" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" 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 "OK" is equal to (button returned of recordResponse) then
  set strResponse to (text returned of recordResponse) as text
else
log "キャンセルしました"
return "キャンセルしました"
end if

set strCommandText to (strResponse) as text
set strResponse to (do shell script strCommandText) as text
###改行でリスト化
set AppleScript's text item delimiters to "\r"
set listResponse to every text item of strResponse
set AppleScript's text item delimiters to ""
###出力初期化
set strOutPutText to "" as text
set strDownlink to "" as text
set strUplink to "" as text
###SUMMARY行以前は出力しない
set boolSUMMARY to false as boolean
###出力行の数だけ繰り返し
repeat with itemLineText in listResponse
  if itemLineText contains "=" then
    set boolSUMMARY to true as boolean
  end if
  if itemLineText contains "Downlink bytes" then
    set strDownlink to itemLineText as text
  end if
  if itemLineText contains "Uplink bytes" then
    set strUplink to itemLineText as text
  end if
  if boolSUMMARY is true then
    set strOutPutText to strOutPutText & itemLineText & "\r" as text
  end if
end repeat

###ダイアログへ戻す
set strMes to ("ネットワーク スピードテスト\r" & strDownlink & "\r" & strUplink & "\r") as text

try
  #####ダイアログを前面に
  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 recordResult to (display dialog strMes with title "ネットワーク スピードテスト" default answer strOutPutText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
log "エラーしました"
return
end try
if true is equal to (gave up of recordResult) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of recordResult) then
  set theResponse to (text returned of recordResult) as text
else if button returned of recordResult is "クリップボードにコピー" then
  try
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strTitle as text
    end tell
  end try
else
return "キャンセル"
end if





|

ping実行例


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


##通常
set strHostName to ("news.yahoo.co.jp") as text

try
  ##オプリョン -c 1 1回だけ送信 -t 2 タイムアウト2秒
  set strCommandText to ("/sbin/ping -c 1 \"" & strHostName & "\" -t 2 &> /dev/null") as text
log (do shell script strCommandText) as text
on error strMes number numErrorNo
  if numErrorNo is 2 then
log strMes
log strHostName & "は名前解決は出来ましたがpingに応答しなかった"
  else if numErrorNo is 68 then
log strHostName
log strHostName & "は名前解決できないのでドメイン落ちしています"
  end if
end try

##名前解決できない場合
set strHostName to ("bahoo.co.jp") as text

try
  set strCommandText to ("/sbin/ping -c 1 \"" & strHostName & "\" -t 2 &> /dev/null") as text
log (do shell script strCommandText) as text
on error strMes number numErrorNo
  if numErrorNo is 2 then
log strMes
log strHostName & "は名前解決は出来ましたがpingに応答しなかった"
  else if numErrorNo is 68 then
log strHostName
log strHostName & "は名前解決できないのでドメイン落ちしています"
  end if
end try

##pingに応答しないケース
set strHostName to ("yahoo.hatena.com") as text

try
  set strCommandText to ("/sbin/ping -c 1 \"" & strHostName & "\" -t 2 &> /dev/null") as text
log (do shell script strCommandText) as text
on error strMes number numErrorNo
  if numErrorNo is 2 then
log strMes
log strHostName & "は名前解決は出来ましたがpingに応答しなかった"
  else if numErrorNo is 68 then
log strHostName
log strHostName & "は名前解決できないのでドメイン落ちしています"
  end if
end try



|

UNIXコマンドの実行


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#ファイルに保存の場合『起動時に削除される項目』内にファイルを作成しますので
#再起動時に削除されますので、普通に閉じてOKなズボラ仕様です
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()


#############################
###ダイアログ
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 strIconFilePath to ("/System/Library/CoreServices/Applications/Wireless Diagnostics.app/Contents/Resources/AppIcon.icns") as text
set aliasIconPath to (POSIX file strIconFilePath) as alias
###設定 ダイアログ テキスト
set strMes to ("オプション指定可能です AaDdfLnoQqRrv\n/sbin/ping6も可能です") as text
set strTitle to ("pingを実行します") as text
###デフォルトのコマンド例
set strDefaultAnswer to ("/sbin/ping -c 10 www.yahoo.co.jp") as text
# set strDefaultAnswer to ("/usr/bin/networkQuality -v -I en0") as text
# set strDefaultAnswer to ("/usr/bin/whois www.yahoo.co.jp") as text
# set strDefaultAnswer to ("/usr/bin/nslookup -type=NS www.yahoo.co.jp") as text
# set strDefaultAnswer to ("/usr/sbin/netstat -i") as text

##ダイアログ
set recordResult to (display dialog strMes with title strTitle default answer strDefaultAnswer buttons {"ファイルにする", "ターミナルで実行", "キャンセル"} default button "ターミナルで実行" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
###
delay 0.1
if (gave up of recordResult) is true then
return "時間切れですやりなおしてください"
else if (gave up of recordResult) is false then
log recordResult as record
end if

if (button returned of recordResult) is "ファイルにする" then
  set strCommandText to (text returned of recordResult) as text
  set strResponse to (do shell script strCommandText) as text
  ##戻り値
  set aliasOpenFile to doExportFile(strResponse) as alias
  ##書き出したファイルURL
  set strOpenFilePath to (POSIX path of aliasOpenFile) as text
  set ocidOpenFilePathStr to refMe's NSString's stringWithString:(strOpenFilePath)
  set ocidOpenFilePath to ocidOpenFilePathStr's stringByStandardizingPath()
  set ocidOpenFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidOpenFilePath) isDirectory:false)
  ##ワークスペースで開く
  set boolResults to (appShardWorkspace's openURL:ocidOpenFilePathURL)
  ##エラーしたらファインダーで開くのを試してみる
  if boolResults is false then
    tell application "Finder"
make new Finder window to aliasFilePathURL
    end tell
  end if
  
return "ファイルにするを実行しました"
else if (button returned of recordResult) is "ターミナルで実行" then
  set strCommandText to (text returned of recordResult) as text
  ###【1】Terminalを全面に
  tell application "Terminal"
activate
  end tell
  ###【2】ウィンドウの数で状態を調べて
  repeat 5 times
    tell application "Terminal"
      set numCntWindow to (count of every window) as integer
    end tell
    if numCntWindow = 0 then
log "window=0はTerminal起動中なので起動を待つ"
delay 0.5
    else if numCntWindow = 1 then
log "window=1は起動済み 全面Terminal無しなので新規windowを生成"
      tell application "Terminal"
do script "\n"
      end tell
      exit repeat
    else
log "Window>1はすでに全面にWindowがある windowがbusy=コマンド実行中か?はこの時点では不明"
      exit repeat
    end if
  end repeat
  ###【3】前面ウィンドウがbusyかを調べる
  tell application "Terminal"
    tell front window
      tell selected tab
        set boolBusy to busy as boolean
      end tell
    end tell
  end tell
  if boolBusy is true then
log "前面Windowコマンド実行中=新規Windowを作成"
    tell application "Terminal"
do script "\n"
    end tell
  else
log "前面Window利用可能"
  end if
  ###【4】全面ウィンドウでコマンドを実行する
  tell application "Terminal"
do script (strCommandText) in selected tab of front window
return "ターミナルで実行"
  end tell
end if



##############################
### テンポラリにテキストファイル
##############################
to doExportFile(argText)
  ##渡されたテキスト
  set strText to argText as text
  set ocidText to refMe's NSString's stringWithString:(strText)
  set ocidReadTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidReadTextM's setString:(ocidText)
  ##改行をUNIX LFに統一
  set ocidReadTextM to ocidReadTextM's stringByReplacingOccurrencesOfString:("\r\n") withString:("\n")
  set ocidReadTextM to ocidReadTextM's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
  ###ディレクトリ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  ###ユニークになるようにフォルダ名はUUID
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  ###フォルダを作る
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  ###保存するテキストファイルへのパス
  set strTimeNO to doGetDateNo("yyyy-MM-dd")
  set strFileName to (strTimeNO & ".txt") as text
  set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
  ##保存
  set listDone to ocidReadTextM's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
  ##
  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePathURL's |path|) |error|:(reference)
  ###エイリアスでパスを戻す
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
return aliasSaveFilePath
end doExportFile


##############################
### 今の日付日間 テキスト
##############################
to doGetDateNo(argDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  ###日付フォーマットを適応
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate)
  ###テキストに確定させて戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


|

IPアドレス取得

www.cloudflare.com の応答速度の速さが決めて

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

#!/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 strURL to "https://www.cloudflare.com/cdn-cgi/trace?json" as text
set ocidURL to refMe's NSURL's URLWithString:(strURL)
###URLをリクエスト
set listContents to refMe's NSString's stringWithContentsOfURL:(ocidURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
set ocidContents to item 1 of listContents
###改行で
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet
###リスト化して
set ocidStringArray to ocidContents's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
###IPアドレスを取得
repeat with itemStringArray in ocidStringArray
  if (itemStringArray as text) starts with "ip" then
    set ocidIPArray to (itemStringArray's componentsSeparatedByString:"=")
    set ocidIPAdd to (ocidIPArray's objectAtIndex:1)
  end if
end repeat
###
set strIPAdd to ocidIPAdd as text
###ホスト名解決
set strCommandText to ("/usr/bin/dig -x " & strIPAdd & " +short")
set strHostName to (do shell script strCommandText) as text

set strCommandText to ("/sbin/ifconfig | grep \"inet.*broadcast\" | awk '{print $2}'") as text
set strLocalIP to (do shell script strCommandText) as text

set strAns to (strHostName & "\r" & strIPAdd & "\r" & strLocalIP & "") as text
##############################
#####ダイアログを前面に出す
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
################################
######ダイアログ
################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
try
  set recordResponse to (display dialog strAns with title "IPアドレス" default answer strAns buttons {"クリップボードにコピー", "OK", "キャンセル"} default button "OK" cancel button "キャンセル" 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 "OK" is equal to (button returned of recordResponse) then
  set strResponse to (text returned of recordResponse) as text
else if button returned of recordResponse is "クリップボードにコピー" then
  set strText to text returned of recordResponse as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  ##結果をペーストボードにテキストで入れる
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
return strText
else
  log "キャンセルしました"
return "キャンセルしました" & strText
end if

log strText as text





|

[SMB]ゲスト接続


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

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

###接続用のURL
set strURL to ("smb://guest:guest@192.168.0.XXX:445/Shared") as text
###クリップボードに入れておいて
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
appPasteboard's clearContents()
appPasteboard's setString:(strURL) forType:(refMe's NSPasteboardTypeString)

#####ダイアログを前面に
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 listURL to {"_afpovertcp._tcp", "_smb._tcp", "_cifs_tcp"} as list
##ダイアログ
set strResults to choose URL strURL showing listURL with editable URL
###NSWorkspaceで開く
###そう、ダイアログいらないよね…笑
set ocidURLstr to refMe's NSString's stringWithString:(strResults)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLstr)
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
appShardWorkspace's openURL:(ocidURL)

return

|

ARPのリセットとリセット結果の表示

do shell scriptを利用することで指紋認証使えるのは便利

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

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


property refMe : a reference to current application


set strCommandText to "/usr/bin/sudo /usr/sbin/arp -a -d" as text

set strResponse to (do shell script strCommandText with administrator privileges) as text

tell application "TextEdit"
  activate
  properties
  make new document with properties {name:"arp", text:strResponse}
end tell

tell application "TextEdit"
  tell front document
    tell its text
      set its font to "Osaka-mono"
      set its size to 14
    end tell
  end tell
end tell

|

[TOOL]IPアドレスの取得

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

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

property refMe : a reference to current application

########################
######ローカルIPアドレスの取得
set objSysInfo to system info
set strLocalIpAdd to (IPv4 address of objSysInfo) as text
set strResponse to "LocalIP: " & strLocalIpAdd & "\n" as text
########################
######グローバルIPGw)の
try
  set strCommandText to "/usr/bin/curl -s api.ipify.org"
  with timeout of 2 seconds
    set strResults to (do shell script strCommandText) as text
  end timeout
on error
  set strCommandText to "/usr/bin/curl -s ifconfig.me"
  with timeout of 10 seconds
    set strResults to (do shell script strCommandText) as text
  end timeout
end try
set strResponse to strResponse & "PublicIP: " & strResults as text
##############################
#####ダイアログを前面に出す
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
(display dialog strResponse with title "IPアドレス" default answer strResponse buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)

|

[nettop]接続中のネットワークサービスの一覧を出力する

左側にMan出す用意してある自分用

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

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


property refMe : a reference to current application


set strCommandText to "/usr/bin/nettop -x -n" as text

tell application "Terminal"
  launch
  activate
  set objTabWindows to do script "\n\n"
  tell objTabWindows
    activate
  end tell
  tell front window
    activate
    set numWidowID to id as integer
  end tell
  
  tell window id numWidowID
    set size to {720, 870}
    set position to {360, 25}
    set origin to {360, 515}
    set frame to {360, 515, 1080, 875}
    set bounds to {360, 25, 1080, 895}
  end tell
  tell objTabWindows
    activate
    do script strCommandText in objTabWindows
  end tell
end tell

set strCommandText to "/usr/bin/man -a nettop"

tell application "Terminal"
  set objTabWindows to do script "\n\n"
  tell front window
    activate
    set numWidowID to id as integer
  end tell
  tell window id numWidowID
    activate
    set size to {360, 870}
    set position to {0, 25}
    set origin to {0, 0}
    set frame to {0, 0, 360, 875}
    set bounds to {0, 25, 360, 900}
  end tell
  tell objTabWindows
    activate
    do script strCommandText in objTabWindows
  end tell
end tell
return

|

[IP]自分のグローバルIPアドレス

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


property refMe : a reference to current application


################################################
###### URL部分
################################################

set strBaseURL to "http://www.geoplugin.net/json.gp?jsoncallback" as text

set coidBaseURLStr to refMe's NSString's stringWithString:strBaseURL
set ocidBaseURL to refMe's NSURL's URLWithString:coidBaseURLStr


################################################
###### URLRequest部分
################################################
set ocidURLRequest to refMe's NSMutableURLRequest's alloc()'s init()
ocidURLRequest's setHTTPMethod:"POST"
ocidURLRequest's setURL:ocidBaseURL
ocidURLRequest's addValue:"application/json" forHTTPHeaderField:"Content-Type"
###ポストするデータは空
ocidURLRequest's setHTTPBody:(missing value)

################################################
###### データ取得
################################################
set ocidServerResponse to refMe's NSURLConnection's sendSynchronousRequest:ocidURLRequest returningResponse:(missing value) |error|:(reference)
###取得JSONデータ 
set ocidJsonResponse to (item 1 of ocidServerResponse)
####取得データをJSONで確定
set ocidJsonData to refMe's NSJSONSerialization's JSONObjectWithData:ocidJsonResponse options:(refMe's NSJSONReadingMutableContainers) |error|:(reference)
####レコードに格納
set ocidJsonDict to (refMe's NSDictionary's alloc()'s initWithDictionary:(item 1 of ocidJsonData))
###必要なレコードを取り出す
log geoplugin_request of ocidJsonDict as text


|

その他のカテゴリー

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