Copy & Paste mit Apple Scripts

Apple Automator

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.

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.

Enter öffnet den Slider, Esc verlässt ihn. Pfeiltasten blättern, Tab springt weiter.

Mehr aus dieser Kategorie

Ein Kommentar

  1. Greetings,

    Thanks for the AppleScrip. It proved to be quite useful for my intention.

    Cheers,

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert