20260323

【macOS】Visual Studio Codeで開くクイック・アクション


【macOS】Visual Studio Codeで開くクイック・アクション

NOTE記事一覧ですnote.com

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

OPEN_VisualStudioCodeWF.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(* 
004Visual Studio Codeでファイルを開く
005スキーム指定版
006Automator.app用
007
008com.cocolog-nifty.quicktimer.icefloe *)
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "AppKit"
013use scripting additions
014
015property refMe : a reference to current application
016
017
018#テキストでファイルURLを整形してOPENする
019on run {listAliasFilePath}
020   
021   repeat with itemAliasFilePath in listAliasFilePath
022      set aliasFilePath to itemAliasFilePath as alias
023      set strFilePath to (POSIX path of aliasFilePath) as text
024      set strFilePath to ("vscode://file/" & strFilePath & "") as text
025      set strCmd to ("/usr/bin/open \"" & strFilePath & "\"") as text
026      do shell script strCmd
027   end repeat
028   return doQuitAutomatorRunner()
029end run
030
031
032
033
034##################################
035#com.apple.automator.xpc.runnerの終了
036to doQuitAutomatorRunner()
037   #terminateAutomaticallyTerminableApplications 自動終了
038   refMe's NSRunningApplication's terminateAutomaticallyTerminableApplications()
039   #
040   set listBundleID to {"com.apple.automator.xpc.runner", "com.apple.automator.xpc.workflowServiceRunner"} as list
041   #terminate 通常終了
042   repeat with itemBundleID in listBundleID
043      set ocidAppArray to (refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(itemBundleID))
044      repeat with itemApp in ocidAppArray
045         itemApp's terminate()
046      end repeat
047   end repeat
048   
049   try
050      tell application "System Events" to quit
051   end try
052   #terminateAutomaticallyTerminableApplications 自動終了
053   refMe's NSRunningApplication's terminateAutomaticallyTerminableApplications()
054end doQuitAutomatorRunner
AppleScriptで生成しました