I want to write a service on macOS, and it only return a string, like my email address. So in any application, if I need input email address, I just hit the same shortcut.

I write a service in automator, and run shell script:

#!/usr/bin echo "my_name@domain.com"

but it only output the text to stdout instead of application input.

  • I just add another step "Copy to Clipboard" and now after I run this service in any application, the string will copy to clipboard and I can use Ctrl+V to get the content directly. But it's not a good implement, because it takes two shortcuts : 1 run service , 2 ctrl +v. It's still not convenient. – Sting Jia Apr 12 '17 at 3:46
  • 2
    Might be easier to use Text Substitution instead (in System Preferences). – nohillside Apr 12 '17 at 17:47
  • Text Substitution is a good way to replace known string. I also need service can do something else, like : output current date/time in specific format. – Sting Jia Apr 14 '17 at 2:41
  • @StingJia How do you want the current date and time to look when output? – wch1zpink Apr 14 '17 at 2:59
  • @wch1zpink I means maybe I need multiple custom service. like: Ctrl+Cmd+M to output my mail address, Ctrl+Cmd+D to output current time(YYYY-MM-DD hh:mm:ss). then when I edit some spreedsheet in Excel, I don't need input same content, just use the shortcut. – Sting Jia Apr 16 '17 at 4:02

You can add a "run applescript" command to your automator workflow

set the clipboard to "my_name@domain.com"
tell application "System Events"
    keystroke (the clipboard)
end tell


tell application "System Events"
    keystroke "my_name@domain.com"
end tell

You can add this AppleScript to your Automator workflow to be able to insert the time and date from your clipboard

set AppleScript's text item delimiters to ","
set theLongDate to (current date)
set theLongDate to (date string of theLongDate)
set currentMonth to (word 1 of text item 2 of theLongDate)
set currentDay to (word 2 of text item 2 of theLongDate)
set currentYear to (word 1 of text item 3 of theLongDate)
set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with x from 1 to 12
    if currentMonth = ((item x of monthList) as string) then
        set theRequestNumber to (text -2 thru -1 of ("0" & x))
        exit repeat
    end if
end repeat
set currentMonth to theRequestNumber
set currentDay to (text -2 thru -1 of ("0" & currentDay))
set theShortDate to (currentMonth & "/" & currentDay & "/" & currentYear) as string
set CurrentTime to (time string of (current date))
set CurrentTimeandShortDate to (theShortDate & " @ " & CurrentTime)

set the clipboard to the result -- the result formatted like this 04/16/2017 @ 12:27:00 AM

-- If you only want to copy the time and date to your clip board without sending the keystrokes, Then comment out the next three lines

tell application "System Events"
    keystroke (the clipboard)  
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .