Skip to main content
previously reverted multiple-item edit; now re-implementing some punctuation edits;
Source Link
Mockman
  • 1.3k
  • 1
  • 8
  • 19

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (ie in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a Run Applescript action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows.:

  • Includes use scripting additions as the clipboard is a focus here
  • Gets and activates the front application so that the command-c keystrokekeystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps, including Firefox and Dictionary itself, without issue.

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (ie in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a Run Applescript action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows.

  • Includes use scripting additions as the clipboard is a focus here
  • Gets and activates the front application so that the command-c keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps including Firefox and Dictionary itself without issue

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (ie in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a Run Applescript action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows:

  • Includes use scripting additions as the clipboard is a focus here
  • Gets and activates the front application so that the command-c keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps, including Firefox and Dictionary itself, without issue.

Rollback to Revision 1
Source Link
Mockman
  • 1.3k
  • 1
  • 8
  • 19

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (i.e.,ie in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a "Run Applescript"Run Applescript action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows:.

  • Includes "use scripting additions"use scripting additions as the clipboard is a focus here
  • Gets and activates the front application so that the Cmd+Ccommand-c keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps, including Firefox and Dictionary itself, without issue.

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (i.e., in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a "Run Applescript" action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows:

  • Includes "use scripting additions" as the clipboard is a focus here
  • Gets and activates the front application so that the Cmd+C keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps, including Firefox and Dictionary itself, without issue.

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (ie in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a Run Applescript action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows.

  • Includes use scripting additions as the clipboard is a focus here
  • Gets and activates the front application so that the command-c keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps including Firefox and Dictionary itself without issue

fixed formatting
Source Link
agarza
  • 2.4k
  • 8
  • 19
  • 29

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (iei.e., in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a Run Applescript"Run Applescript" action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows.:

  • Includes use scripting additions"use scripting additions" as the clipboard is a focus here
  • Gets and activates the front application so that the command-cCmd+C keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps, including Firefox and Dictionary itself, without issue.

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (ie in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a Run Applescript action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows.

  • Includes use scripting additions as the clipboard is a focus here
  • Gets and activates the front application so that the command-c keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps including Firefox and Dictionary itself without issue

As the @red_menace suggests, the nature of how this script is called is unclear. I've made the assumption that it will be called using an Automator workflow that is accessed via the script menu (i.e., in the User's Library > Scripts folder. Of course, adjustments can be made for different approaches.

The following should be placed inside a "Run Applescript" action.

use scripting additions
on run {input, parameters}
    
    tell application "System Events"
        set frontApp to name of first application process whose frontmost is true
    end tell
    set oldClipboard to the clipboard
    
    tell application frontApp
        activate
        tell application "System Events"
            tell application process frontApp
                keystroke "c" using command down
                delay 0.1
            end tell
        end tell
        set theWord to first word of (the clipboard as «class utf8»)
        delay 0.1
    end tell
    
    -- Log file path
    set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
    do shell script "touch " & quoted form of logPath
    
    -- Append the word to the log
    do shell script "echo " & quoted form of theWord & " >> " & quoted form of logPath
    
    -- Open Dictionary to that word
    do shell script "open dict://" & quoted form of theWord
    
    -- Restore clipboard
    set the clipboard to oldClipboard
end run

The additions to the OP script are as follows:

  • Includes "use scripting additions" as the clipboard is a focus here
  • Gets and activates the front application so that the Cmd+C keystroke has something to work on
  • Truncates after first word so that the log file doesn't collect extraneous verbiage
  • Explicitly use utf-8

I tested it on a few apps, including Firefox and Dictionary itself, without issue.

Source Link
Mockman
  • 1.3k
  • 1
  • 8
  • 19
Loading