Deepl翻訳用クイックアクション
ダウンロードはこちら
【スクリプトエディタで開く】 |
Open_DeepLtranslate.applescript.scpt | ソース |
|---|
| 001 | #!/usr/bin/osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | オートメーター・クイックアクション用 |
| 006 | deepl翻訳サイトを開いて翻訳結果を表示します |
| 007 |
|
| 008 | com.cocolog-nifty.quicktimer.icefloe *) |
| 009 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 010 | use AppleScript version "2.8" |
| 011 | use framework "Foundation" |
| 012 | use framework "AppKit" |
| 013 | use framework "NaturalLanguage" |
| 014 | use scripting additions |
| 015 | property refMe : a reference to current application |
| 016 |
|
| 017 | on 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 |
| 023 | end run |
| 024 |
|
| 025 | on 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 |
| 048 | end open |
| 049 |
|
| 050 |
|
| 051 | ############################## |
| 052 | to 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 |
| 068 | end doQuitSelf |
| 069 |
|
| AppleScriptで生成しました |
|---|