20260411

Deepl翻訳用クイックアクション

Deepl翻訳用クイックアクション

ダウンロードはこちら
NOTE記事一覧ですnote.com

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

Open_DeepLtranslate.applescript.scpt
ソース
001#!/usr/bin/osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
004(*
005オートメーター・クイックアクション用
006deepl翻訳サイトを開いて翻訳結果を表示します
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 framework "NaturalLanguage"
014use scripting additions
015property refMe : a reference to current application
016
017on run {strSelectedString}
018   #on run
019   #set strSelectedString to ("テスト用文言") as text
020   set strSelectedString to strSelectedString as text
021   set strURL to (open strSelectedString) as string
022   return strURL
023end run
024
025on open strSelectedString
026   set ocidSelectedString to refMe's NSString's stringWithString:(strSelectedString)
027   set appNatural to (refMe's NSLinguisticTagger)
028   set ocidLang to appNatural's dominantLanguageForString:(ocidSelectedString)
029   log ocidLang as list
030   if ocidLang = (missing value) then
031      set strLang to "en" as text
032   else
033      set strLang to ocidLang as text
034   end if
035   
036   if strLang is "en" then
037      set strURL to ("https://www.deepl.com/ja/translator#en/ja/" & strSelectedString & "") as text
038   else if strLang is "ja" then
039      set strURL to ("https://www.deepl.com/ja/translator#ja/en-us/" & strSelectedString & "") as text
040   else
041      set strURL to ("https://www.deepl.com/ja/translator#" & strLang & "/ja/" & strSelectedString & "") as text
042   end if
043   set ocidURLString to refMe's NSString's stringWithString:(strURL)
044   set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
045   set strURL to ocidURL's absoluteString() as text
046   
047   return strURL
048end open
049
050
051##############################
052to doQuitSelf()
053   try
054      tell application "System Events" to quit
055   end try
056   set strOutputString to (missing value)
057   set listAliasFilePath to (missing value)
058   set listBundleID to {"com.apple.automator.xpc.runner", "com.apple.automator.xpc.workflowServiceRunner"} as list
059   repeat with itemBundleID in listBundleID
060      set ocidAppArray to (refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(itemBundleID))
061      repeat with itemApp in ocidAppArray
062         try
063            set boolDone to itemApp's terminate()
064         end try
065      end repeat
066   end repeat
067   return true
068end doQuitSelf
069
AppleScriptで生成しました