+49 (0) 160 843 6001 info@nextab.de

Copy & Paste mit Apple Scripts

Heute hatte ich mit einer extrem repetitiven Aufgabe zu kämpfen, die prinzipiell darin bestand, Inhalte aus einem Programm in ein anderes zu kopieren, dann einige kleinere Änderungen vorzunehmen bzw. ein Excel-Skript für mich ein Ergebnis berechnen zu lassen und das Ergebnis dann wieder in Firefox einzufügen. Anschließend musste dieser recht stumpfe Task wiederholt werden. Mehr als 1.400 Mal.

Nachdem ich rund 300 Einträge von Hand eingetippt hatte, sah ich mich nach einer besseren Lösung um und stieß so wieder einmal auf Automator. Diese Software ist standardmäßig in Mac OSX enthalten (ich arbeite seit einiger Zeit auf einem Mac, wer sich näher dafür interessiert, sollte mal meine Umstiegs-Serie auf meinem persönlichen Blog lesen) und ermöglicht es, umfangreiche Macros zu erstellen. Diese funktionieren sogar, wenn sie mehrere Programme involvieren.

Ich habe ein kleines (englisches) Video erstellt, in dem ich die Funktionsweise des Scripts etwas näher erläutere:

Hier nun noch der Quellcode des Apple Scripts:

repeat 25 times

tell application "Firefox" to activate
tell application "System Events"
tell process "Firefox"
keystroke "c" using command down
keystroke tab
end tell
end tell

delay 0.3

tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Microsoft Excel"
keystroke "v" using command down
keystroke tab
end tell
end tell

delay 0.3

tell application "Firefox" to activate
tell application "System Events"
tell process "Firefox"
keystroke "c" using command down
end tell
end tell

delay 0.3

tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Microsoft Excel"
keystroke "v" using command down
delay 0.3
keystroke tab
delay 0.4
keystroke "c" using command down
end tell
end tell

delay 0.3

tell application "Firefox" to activate
tell application "System Events"
tell process "Firefox"
keystroke "v" using command down
keystroke tab
keystroke tab
keystroke tab
keystroke tab
end tell
end tell

delay 0.3

tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Microsoft Excel"
keystroke return
end tell
end tell

delay 0.3

end repeat

Eigene Anpassungen sollten schnell von der Hand geben, ansonsten nehmt einfach Kontakt mit uns auf und wir gehen euch gerne zur Hand.

Wir freuen uns selbstverständlich wie immer über Feedback.

Über Oliver Gehrmann

Oliver Gehrmann ist Gründer der Agentur nexTab, Fan von Sammelkartenspielen, verheiratet und Vater von zwei Jungs, von denen gerüchteweise sogar vereinzelt Bilder in dieser Webseite eingearbeitet sind...