From 018cc2bad2e8bf29914d39b0119e836fa0f9dc18 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Sat, 4 Jan 2025 11:30:32 +0800 Subject: [PATCH] support Bob.app old version <= 1.5.0 AppleScript API translate --- external-dict.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/external-dict.el b/external-dict.el index 455d420..77f7f46 100644 --- a/external-dict.el +++ b/external-dict.el @@ -169,11 +169,22 @@ it will raise external dictionary main window." ;;;###autoload (defun external-dict-Bob.app-translate (text) "Translate TEXT in Bob.app." - (let ((path "translate") - (action "translateText") - (text text)) - (ns-do-applescript - (format "use scripting additions + (if (version<= + (ns-do-applescript + "tell application \"Bob\" +version +end tell") + "1.5.0") + (ns-do-applescript + (format "tell application id \"com.hezongyidev.Bob\" + launch + translate \"%s\" +end tell" text)) + (let ((path "translate") + (action "translateText") + (text text)) + (ns-do-applescript + (format "use scripting additions use framework \"Foundation\" on toJson(recordValue) (((current application's NSString)'s alloc)'s initWithData:((current application's NSJSONSerialization)'s dataWithJSONObject:recordValue options:1 |error|:(missing value)) encoding:4) as string @@ -183,7 +194,7 @@ set theRecord to {|path|: \"%s\", body: {action: \"%s\", |text|: \"%s\", windowL set theParameter to toJson(theRecord) tell application id \"com.hezongyidev.Bob\" to request theParameter " - path action text)))) + path action text))))) (defun external-dict-Bob.app-dictionary (word) "Query WORD in macOS Bob.app." -- 2.11.4.GIT