プロセス名 process 『VSCode』→『Code』
アプリケーションプロセス名 application process 『Electron』→『Code』
と
変わったようです
【スクリプトエディタで開く】 |
ファイル名取得.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | use AppleScript version "2.8" |
| 004 | use scripting additions |
| 005 |
|
| 006 | ########################################## |
| 007 | #ファイル名の取得を試みる |
| 008 | tell 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 |
| 020 | end tell |
| 021 |
|
| 022 |
|
| 023 |
|
| 024 | try |
| 025 | tell application "System Events" to quit |
| 026 | end try |
| 027 |
|
| 028 | return |
| AppleScriptで生成しました |
|---|
【スクリプトエディタで開く】 |
ファイル名取得.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | use AppleScript version "2.8" |
| 004 | use scripting additions |
| 005 |
|
| 006 | ########################################## |
| 007 | #ファイル名の取得を試みる |
| 008 | tell 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 |
| 021 | end tell |
| 022 |
|
| 023 |
|
| 024 |
|
| 025 | try |
| 026 | tell application "System Events" to quit |
| 027 | end try |
| 028 |
|
| 029 | return |
| AppleScriptで生成しました |
|---|
【スクリプトエディタで開く】 |
ファイルのパス.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | use AppleScript version "2.8" |
| 004 | use scripting additions |
| 005 |
|
| 006 | ########################################## |
| 007 | #前面Windowのパスの取得を試みる |
| 008 | set strFilePath to doCopyPathVsCode() |
| 009 |
|
| 010 | log strFilePath |
| 011 | try |
| 012 | tell application "System Events" to quit |
| 013 | end try |
| 014 |
|
| 015 | return strFilePath |
| 016 |
|
| 017 |
|
| 018 |
|
| 019 | ################################ |
| 020 | ######パスコピーVScode |
| 021 | ################################ |
| 022 |
|
| 023 | to 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 |
| 053 | end doCopyPathVsCode |
| AppleScriptで生成しました |
|---|
【スクリプトエディタで開く】 |
選択中のテキストコピー.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | use AppleScript version "2.8" |
| 004 | use scripting additions |
| 005 |
|
| 006 |
|
| 007 | tell 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 |
| 018 | end tell |
| 019 | delay 0.25 |
| 020 | set theText to (the clipboard as text) |
| 021 |
|
| 022 | log theText |
| 023 |
|
| 024 | try |
| 025 | tell application "System Events" to quit |
| 026 | end try |
| 027 |
|
| 028 | return theText |
| AppleScriptで生成しました |
|---|
【スクリプトエディタで開く】 |
基本(com.microsoft.VSCode).scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | Visual Studio Codeのプロセス名が変わったことに対応する |
| 006 | 基本的な流れ |
| 007 |
|
| 008 |
|
| 009 | com.cocolog-nifty.quicktimer.icefloe *) |
| 010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 011 | use AppleScript version "2.8" |
| 012 | use scripting additions |
| 013 |
|
| 014 | #バンドルIDを別指定することでTRYでエラーになる |
| 015 | set strBundleID to ("com.microsoft.VSCode") as text |
| 016 |
|
| 017 | ######################## |
| 018 | #起動確認 |
| 019 | try |
| 020 | tell application id strBundleID to if (not running) then launch |
| 021 | on error strErrMsg number numErrNo |
| 022 | #アプリケーションが見つからないか未インストールかどちらか |
| 023 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 024 | return false |
| 025 | end try |
| 026 |
|
| 027 | ######################## |
| 028 | #起動待ち |
| 029 | repeat 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 |
| 039 | end repeat |
| 040 | #この時点で起動している『はず』 |
| 041 |
|
| 042 | ######################## |
| 043 | #アプリケーションのパスを取得して |
| 044 | tell 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 |
| 052 | end tell |
| 053 |
|
| 054 | ######################## |
| 055 | #バージョン取得 |
| 056 | set recordInfoFor to (info for aliasAppApth) as record |
| 057 | set strVersion to (short version of recordInfoFor) as text |
| 058 |
|
| 059 | #カンマ区切りのバージョンテキストを数値にする |
| 060 | set strDelim to AppleScript's text item delimiters |
| 061 | set AppleScript's text item delimiters to "." |
| 062 | set listVersion to every text item of strVersion |
| 063 | set listVersionShort to (items 1 thru 2 of listVersion) as list |
| 064 | set strVersion to listVersionShort as text |
| 065 | set AppleScript's text item delimiters to strDelim |
| 066 | set numVersion to strVersion as number |
| 067 |
|
| 068 | #バージョンの違いによる分岐 |
| 069 | if 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 |
| 079 | else |
| 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 |
| 089 | end if |
| 090 |
|
| 091 | ######################## |
| 092 | #Windowが無いならWindowを作って |
| 093 | if 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 |
| 105 | end if |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 | try |
| 113 | tell application "System Events" to quit |
| 114 | end try |
| 115 |
|
| 116 | return |
| AppleScriptで生成しました |
|---|