1 votes

Comment écrire un service pour obtenir une chaîne de caractères ?

Je veux écrire un service sur MacOS, et il ne renvoie qu'une chaîne de caractères, comme mon adresse email. Ainsi, dans n'importe quelle application, si j'ai besoin de saisir mon adresse électronique, il me suffit d'appuyer sur le même raccourci.

J'écris un service dans automator, et j'exécute le shell script :

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

mais il ne sort le texte que sur stdout au lieu de l'entrée de l'application.

0 votes

I

2 votes

M

0 votes

T

1voto

wch1zpink Points 6067

Vous pouvez ajouter une commande "run applescript" à votre workflow automator

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

OU

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

Vous pouvez ajouter cet AppleScript à votre flux de travail Automator pour pouvoir insérer l'heure et la date à partir de votre presse-papiers.

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

LesApples.com

LesApples est une communauté de Apple où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres utilisateurs d'appareils Apple, poser vos propres questions ou résoudre celles des autres.

Powered by:

X