AppleScript Translate

【日英判定】Safari google翻訳


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set appFileManager to refMe's NSFileManager's defaultManager()

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "入力してください" as text
  end if
end if

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("【日英判定】翻訳します\rSafariで開きます\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
set ocidText to refMe's NSString's stringWithString:(strReturnedText)
###########################
###URL整形 URLコンポーネントを使う
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
##スキームとホスト
ocidURLComponents's setScheme:("https")
ocidURLComponents's setHost:("translate.google.com")
##クエリーアイテムにセットするArray
set ocidQueryItemArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0

###########################
###【日本語判定】大まかな日本語陵域
set ocidPattern to refMe's NSString's stringWithString:("[ぁ-んァ-ン一-鿿]+")
###正規表現を定義↑のパターンでセット
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:(ocidPattern) options:(0) |error|:(reference)
##error referenceしているので戻り値はリストだから
set ocidRegex to (item 1 of listRegex)
###入力文字列のレンジ
set ocidImputRange to refMe's NSMakeRange(0, ocidText's |length|())
###文字列の中に正規表現が最初に当てはまるレンジは?
set ocidRange to ocidRegex's rangeOfFirstMatchInString:(ocidText) options:0 range:(ocidImputRange)
###レンジのロケーションを取り出して
set ocidLocation to ocidRange's location()
##NSNotFoundなら
if ocidLocation = refNSNotFound then
  log "日本語を含みません 日本語に翻訳します"
  ##元テキスト autoも可
  set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("sl") value:("en")
ocidQueryItemArray's addObject:(ocidQueryItem)
  ##翻訳後の言語
  set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("tl") value:("ja")
ocidQueryItemArray's addObject:(ocidQueryItem)
  ##ユーザーインターフェイスの言語 USで英語 JP で日本語
  set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("hl") value:("us")
ocidQueryItemArray's addObject:(ocidQueryItem)
  
else
  ###あるなら
  log "日本語を含みます 英語に翻訳します"
  ##元テキスト autoも可
  set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("sl") value:("ja")
ocidQueryItemArray's addObject:(ocidQueryItem)
  ##翻訳後の言語
  set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("tl") value:("en")
ocidQueryItemArray's addObject:(ocidQueryItem)
  ##ユーザーインターフェイスの言語 USで英語 JP で日本語
  set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("hl") value:("jp")
ocidQueryItemArray's addObject:(ocidQueryItem)
  
end if
###########################
###言語に影響ないクエリーの残り
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("op") value:("translate")
ocidQueryItemArray's addObject:(ocidQueryItem)
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("text") value:(strReturnedText)
ocidQueryItemArray's addObject:(ocidQueryItem)
##全てのクエリーをセット
ocidURLComponents's setQueryItems:(ocidQueryItemArray)
###URLに
set ocidURL to ocidURLComponents's |URL|
set strGetURL to ocidURL's absoluteString() as text

#############
###Safari
###Safariで開く
tell application "Safari" to launch
tell application "Safari"
  activate
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every window) as integer
  ###ウィンドウがなければ
  if numCntWindow = 0 then
    ###新規でウィンドウを作る
make new document with properties {name:strReturnedText}
    tell front window
      open location strGetURL
    end tell
  else
    ###ウィンドウがあるなら新規タブで開く
    tell front window
make new tab
      tell current tab
open location strGetURL
      end tell
    end tell
  end if
end tell

#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ##テキスト形式に確定
  set strTextToEncode to ocidArgTextEncoded as text
  ###値を戻す
return strTextToEncode
end doUrlEncode




|

【日英判定】Safari_mirai_translate 翻訳


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set appFileManager to refMe's NSFileManager's defaultManager()

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "入力してください" as text
  end if
end if

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("【日英判定】翻訳します\rSafariで開きます\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
set ocidText to refMe's NSString's stringWithString:(strReturnedText)
###NSURLを使わないのでクエリー用に%エンコードしておく
set strEncText to doUrlEncode(strReturnedText)
set ocidEncText to refMe's NSString's stringWithString:(strEncText)
###########################
###URL整形
set strURL to ("https://miraitranslate.com/trial/") as text
set ocidBaseURL to refMe's NSString's stringWithString:(strURL)
##
(*
auto 自動
ja 日本
en 英語
ko 韓国
zh 北京語
zt 台湾語
it イタリア
id インドネシア
uk ウクライナ
es スペイン
th タイ
de ドイツ
fr フランス
vi ベトナム
pt ポルトガル
ru ロシア
*)


###########################
###【日本語判定】大まかな日本語陵域
set ocidPattern to refMe's NSString's stringWithString:("[ぁ-んァ-ン一-鿿]+")
###正規表現を定義↑のパターンでセット
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:(ocidPattern) options:(0) |error|:(reference)
##error referenceしているので戻り値はリストだから
set ocidRegex to (item 1 of listRegex)
###入力文字列のレンジ
set ocidImputRange to refMe's NSMakeRange(0, ocidText's |length|())
###文字列の中に正規表現が最初に当てはまるレンジは?
set ocidRange to ocidRegex's rangeOfFirstMatchInString:(ocidText) options:0 range:(ocidImputRange)
###レンジのロケーションを取り出して
set ocidLocation to ocidRange's location()
##NSNotFoundなら
if ocidLocation = refNSNotFound then
  log "日本語を含みません 日本語に翻訳します"
  ##
  set ocidEncBaseURL to ocidBaseURL's stringByAppendingPathComponent:("#en/ja/")
else
  ###あるなら
  set ocidEncBaseURL to ocidBaseURL's stringByAppendingPathComponent:("#ja/en/")
  
end if
###########################
###
set ocidGetURL to ocidEncBaseURL's stringByAppendingPathComponent:(ocidEncText)
set strGetURL to ocidGetURL as text

#############
###Safari
###Safariで開く
tell application "Safari" to launch
tell application "Safari"
  activate
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every window) as integer
  ###ウィンドウがなければ
  if numCntWindow = 0 then
    ###新規でウィンドウを作る
make new document with properties {name:strReturnedText}
    tell front window
      open location strGetURL
    end tell
  else
    ###ウィンドウがあるなら新規タブで開く
    tell front window
make new tab
      tell current tab
open location strGetURL
      end tell
    end tell
  end if
end tell

#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ##テキスト形式に確定
  set strTextToEncode to ocidArgTextEncoded as text
  ###値を戻す
return strTextToEncode
end doUrlEncode




|

【英→日】Safari_mirai_translate


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "入力してください" as text
  end if
end if


###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("【英→日】翻訳します\rSafariで開きます\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if

set strEncText to doUrlEncode(strReturnedText)
set ocidEncText to refMe's NSString's stringWithString:(strEncText)
#############
###URL整形
set strURL to ("https://miraitranslate.com/trial/") as text
set ocidBaseURL to refMe's NSString's stringWithString:(strURL)
##
(*
auto 自動
ja 日本
en 英語
ko 韓国
zh 北京語
zt 台湾語
it イタリア
id インドネシア
uk ウクライナ
es スペイン
th タイ
de ドイツ
fr フランス
vi ベトナム
pt ポルトガル
ru ロシア
*)
set ocidJa2EnURL to ocidBaseURL's stringByAppendingPathComponent:("#ja/en/")
set ocidEn2JaURL to ocidBaseURL's stringByAppendingPathComponent:("#en/ja/")
##
set ocidJa2EnURL to ocidJa2EnURL's stringByAppendingPathComponent:(ocidEncText)
set ocidEn2JaURL to ocidEn2JaURL's stringByAppendingPathComponent:(ocidEncText)
##
set strGetURL to ocidJa2EnURL as text
set strGetURL to ocidEn2JaURL as text

#############
###Safari
###Safariで開く
tell application "Safari" to launch
tell application "Safari"
  activate
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every window) as integer
  ###ウィンドウがなければ
  if numCntWindow = 0 then
    ###新規でウィンドウを作る
make new document with properties {name:strReturnedText}
    tell front window
      open location strGetURL
    end tell
  else
    ###ウィンドウがあるなら新規タブで開く
    tell front window
make new tab
      tell current tab
open location strGetURL
      end tell
    end tell
  end if
end tell

#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ##テキスト形式に確定
  set strTextToEncode to ocidArgTextEncoded as text
  ###値を戻す
return strTextToEncode
end doUrlEncode




|

【日→英】Safari_mirai_translate


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "入力してください" as text
  end if
end if


###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("【日→英】翻訳します\rSafariで開きます\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if

set strEncText to doUrlEncode(strReturnedText)
set ocidEncText to refMe's NSString's stringWithString:(strEncText)
#############
###URL整形
set strURL to ("https://miraitranslate.com/trial/") as text
set ocidBaseURL to refMe's NSString's stringWithString:(strURL)
##
set ocidJa2EnURL to ocidBaseURL's stringByAppendingPathComponent:("#ja/en/")
set ocidEn2JaURL to ocidBaseURL's stringByAppendingPathComponent:("#en/ja/")
##
set ocidJa2EnURL to ocidJa2EnURL's stringByAppendingPathComponent:(ocidEncText)
set ocidEn2JaURL to ocidEn2JaURL's stringByAppendingPathComponent:(ocidEncText)
##
set strGetURL to ocidEn2JaURL as text
set strGetURL to ocidJa2EnURL as text

#############
###Safari
###Safariで開く
tell application "Safari" to launch
tell application "Safari"
  activate
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every window) as integer
  ###ウィンドウがなければ
  if numCntWindow = 0 then
    ###新規でウィンドウを作る
make new document with properties {name:strReturnedText}
    tell front window
      open location strGetURL
    end tell
  else
    ###ウィンドウがあるなら新規タブで開く
    tell front window
make new tab
      tell current tab
open location strGetURL
      end tell
    end tell
  end if
end tell

#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ##テキスト形式に確定
  set strTextToEncode to ocidArgTextEncoded as text
  ###値を戻す
return strTextToEncode
end doUrlEncode




|

[翻訳][python3] mirai-translateで翻訳

ダウンロード - python3_mirai_translate.zip


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# USE
# https://pypi.org/project/mirai-translate/
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "入力してください" as text
  end if
end if


###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("【日→英】翻訳します\r少し時間がかかります\r約5秒") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
set strResponseText to doReplace(strReturnedText, "\"", "\\\"")
set strResponseText to doReplace(strResponseText, "\r", " ")
set strResponseText to doReplace(strResponseText, "\n", " ")
############
set strCommandText to ("/usr/bin/which python3") as text
try
  set strBinPath to (do shell script strCommandText) as text
on error
  try
    ## do shell script "/usr/bin/xcode-select --install"
  end try
return "python3未インストールです"
end try

set strCommandText to ("\"" & strBinPath & "\" -c \"from mirai_translate import Client; cli = Client(); print(cli.translate('" & strResponseText & "', 'ja', 'en'));\"") as text
set strResponse to (do shell script strCommandText) as text

set strResponse to (strReturnedText & "\n" & strResponse & "\n")

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("戻り値です") as text
set strMes to ("戻り値です") as text
set recordResult to (display dialog strMes with title strTitle default answer strResponse buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "クリップボードにコピー" then
  try
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strTitle as text
    end tell
  end try
end if




#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace




|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom