20260313

[AppleScript] Visual Studio Codeのプロセス名が変わりました(Electron→Code)


プロセス名 process 『VSCode』→『Code』
アプリケーションプロセス名 application process 『Electron』→『Code』

変わったようです

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

ファイル名取得.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003use AppleScript version "2.8"
004use scripting additions
005
006##########################################
007#ファイル名の取得を試みる
008tell application id "com.microsoft.VSCode"
009   tell application "System Events"
010      tell process "Code"
011         tell front window
012            try
013               set strFileName to name as text
014            on error strErrMsg number numErrNo
015               set strFileName to "名称未設定.css" as text
016            end try
017         end tell
018      end tell
019   end tell
020end tell
021
022
023
024try
025   tell application "System Events" to quit
026end try
027
028return
AppleScriptで生成しました

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

ファイル名取得.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003use AppleScript version "2.8"
004use scripting additions
005
006##########################################
007#ファイル名の取得を試みる
008tell application id "com.microsoft.VSCode"
009   tell application "System Events"
010      #         tell application process "Electron"
011      tell application process "Code"
012         tell front window
013            try
014               set strFileName to name as text
015            on error strErrMsg number numErrNo
016               set strFileName to "名称未設定.css" as text
017            end try
018         end tell
019      end tell
020   end tell
021end tell
022
023
024
025try
026   tell application "System Events" to quit
027end try
028
029return
AppleScriptで生成しました

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

ファイルのパス.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003use AppleScript version "2.8"
004use scripting additions
005
006##########################################
007#前面Windowのパスの取得を試みる
008set strFilePath to doCopyPathVsCode()
009
010log strFilePath
011try
012   tell application "System Events" to quit
013end try
014
015return strFilePath
016
017
018
019################################
020######パスコピーVScode
021################################
022
023to doCopyPathVsCode()
024   ###前面に出して
025   tell application "System Events"
026      launch
027   end tell
028   tell application "System Events"
029      activate
030   end tell
031   tell application id "com.microsoft.VSCode"
032      activate
033   end tell
034   delay 0.1
035   ###パス取得
036   tell application id "com.microsoft.VSCode"
037      tell application "System Events"
038         #         tell application process "Electron"
039         tell application process "Code"
040            key down {command}
041            keystroke "k"
042            key up {command}
043            delay 0.1
044            key down {option, command}
045            keystroke "c"
046            key up {option, command}
047         end tell
048      end tell
049   end tell
050   delay 0.25
051   set strFilePath to the clipboard as text
052   return strFilePath
053end doCopyPathVsCode
AppleScriptで生成しました

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

選択中のテキストコピー.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003use AppleScript version "2.8"
004use scripting additions
005
006
007tell application id "com.microsoft.VSCode"
008   activate
009   tell application "System Events"
010      #      tell process "VSCode"
011      #      tell process "Electron"
012      tell process "Code"
013         try
014            keystroke "c" using command down
015         end try
016      end tell
017   end tell
018end tell
019delay 0.25
020set theText to (the clipboard as text)
021
022log theText
023
024try
025   tell application "System Events" to quit
026end try
027
028return theText
AppleScriptで生成しました

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

基本(com.microsoft.VSCode).scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
004(* 
005Visual Studio Codeのプロセス名が変わったことに対応する
006基本的な流れ
007
008
009com.cocolog-nifty.quicktimer.icefloe *)
010----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
011use AppleScript version "2.8"
012use scripting additions
013
014#バンドルIDを別指定することでTRYでエラーになる
015set strBundleID to ("com.microsoft.VSCode") as text
016
017########################
018#起動確認
019try
020   tell application id strBundleID to if (not running) then launch
021on error strErrMsg number numErrNo
022   #アプリケーションが見つからないか未インストールかどちらか
023   log "No: " & numErrNo & linefeed & "Error:" & strErrMsg
024   return false
025end try
026
027########################
028#起動待ち
029repeat 40 times
030   tell application id strBundleID
031      set boolFrontMost to frontmost as boolean
032   end tell
033   if boolFrontMost is false then
034      tell application id strBundleID to activate
035   else
036      exit repeat
037   end if
038   delay 0.2
039end repeat
040#この時点で起動している『はず』
041
042########################
043#アプリケーションのパスを取得して
044tell application "Finder"
045   try
046      set aliasAppApth to (application file id strBundleID) as alias
047   on error strErrMsg number numErrNo
048      #アプリケーションが見つからない場合はここで終了
049      log "No: " & numErrNo & linefeed & "Error:" & strErrMsg
050      return false
051   end try
052end tell
053
054########################
055#バージョン取得
056set recordInfoFor to (info for aliasAppApth) as record
057set strVersion to (short version of recordInfoFor) as text
058
059#カンマ区切りのバージョンテキストを数値にする
060set strDelim to AppleScript's text item delimiters
061set AppleScript's text item delimiters to "."
062set listVersion to every text item of strVersion
063set listVersionShort to (items 1 thru 2 of listVersion) as list
064set strVersion to listVersionShort as text
065set AppleScript's text item delimiters to strDelim
066set numVersion to strVersion as number
067
068#バージョンの違いによる分岐
069if numVersion < 1.11 then
070   ########################
071   #Windowの数を数えて【Electron】
072   tell application id strBundleID
073      tell application "System Events"
074         tell application process "Electron"
075            set numCntWindow to (count of every window) as integer
076         end tell
077      end tell
078   end tell
079else
080   ########################
081   #Windowの数を数えて【Code】
082   tell application id strBundleID
083      tell application "System Events"
084         tell process "Code"
085            set numCntWindow to (count of every window) as integer
086         end tell
087      end tell
088   end tell
089end if
090
091########################
092#Windowが無いならWindowを作って
093if numCntWindow = 0 then
094   tell application "Finder"
095      try
096         set aliasAppApth to (application file id strBundleID) as alias
097      on error strErrMsg number numErrNo
098         #アプリケーションが見つからない場合はここで終了
099         log "No: " & numErrNo & linefeed & "Error:" & strErrMsg
100         return false
101      end try
102      #Finder でOPENすることでWindowができる
103      open aliasAppApth
104   end tell
105end if
106
107
108
109
110
111
112try
113   tell application "System Events" to quit
114end try
115
116return
AppleScriptで生成しました