Send to Kindle automatisieren

gandalf12

Aktives Mitglied
Thread Starter
Dabei seit
23.03.2011
Beiträge
472
Reaktionspunkte
62
Hallo,
ich habe mir mit Hazel und Automator einen Arbeitsablauf erstellt der folgendes macht.
Ich lade mir eine Tageszeitung mit Safari in den Download Ordner. Hazel verschiebt die Zeitung dann in entsprechende Ordner/Unterordner und benennt die Zeitung im PDF Format um. Es wird nun die Send to Kindle App gestartet und das PDF wird zu Amazon übertragen. Es läuft soweit auch alles, nur das senden mit der App will nicht klappen da ich nicht weiß wie ich die Kindle App dazu bringe den Send Button per Script zu aktivieren.
Hier ein paar Screenshots:
Der Automatorablauf
Automator.jpg

Die Kindle App
sendtokindle.jpg

Hier noch mal die Skripte im Detail
Code:
on run {input, parameters}
	set supportedTypes to {"txt", "doc", "docx", "rtf", "pdf", "png", "jpg", "jpeg", "bmp", "gif", "azw", "mobi", "prc"}
	set numSupportedDocuments to 0
	repeat with thisItem in input
		set thisItem to thisItem as text
		set thisItem to quoted form of POSIX path of thisItem
		set currentType to do shell script "echo " & thisItem & " | sed 's/\\(.*\\)\\(\\.\\)\\(.*\\)/\\3/g' | tr '[A-Z]' '[a-z]'"
		if supportedTypes contains currentType then
			set numSupportedDocuments to (numSupportedDocuments + 1)
			if numSupportedDocuments > 25 then
				set titleMsg to "Send to Kindle error"
				display alert "Maximum of 25 supported documents can be sent at a  time." as warning
				return {}
			end if
		end if
	end repeat
	return input
end run

und
Code:
#!/usr/bin/perl

if (@ARGV == 0) {
	exit;
}

my $args;
my $file;

$args="-cmd send -launcher shellextension";
$stkApp="/Applications/Send to Kindle/Send to Kindle.app";

foreach (@ARGV) {
    $file="$_";
    $args=$args." -file ".'"'.$file.'"'
}

system("open -n '$stkApp' --args $args");

Wie gesagt es funktioniert alles bis auf den Sendevorgang.
ich habe es auch schon z.B. mit folgendem versucht:
Code:
tell application "System Events"
	click button "Send" of window "SendtoKindle" of process "Send to Kindle"
end tell
will aber leider nicht funktionieren....
Hätte bitte jemand einen Tipp wie es mit der Kindle App funktionieren könnte????

P.S. Mit dem Mailprogramm habe ich das ganze per Skript hinbekommen. (Mail an Kindle.com).
Diese Lösung ist für mich jedoch Suboptimal, da ich mein MailPostfach nicht mit dem Täglichen senden der Tageszeitung zuspammen möchte.
Also wenn bitte jemand eine Idee für den Send Button hätte. Das wäre schon die Goldrandlösung.
Danke
 
Hi,

die SendToKindle-App ist leider unschön programmiert, so sollte es aber trotzdem funktionieren:

Code:
[FONT=Verdana][size=2][b]tell[/b] [color=#0000FF][i]application[/i][/color] "Send to Kindle"
	[color=#0000FF][b]activate[/b][/color] [color=#4C4D4D]--Programm in den Vordergrund holen[/color]
	[b]tell[/b] [color=#0000FF][i]application[/i][/color] "System Events"
		[b]tell[/b] [color=#0000FF][i]process[/i][/color] "SendToKindle"
			[color=#0000FF][b]key code[/b][/color] 76 [color=#4C4D4D]--Enter drücken[/color]
		[b]end[/b] [b]tell[/b]
	[b]end[/b] [b]tell[/b]
[b]end[/b] [b]tell[/b][/size][/FONT]

PS: Du sparst einiges an Code, wenn du die Dateiendung mit

Code:
[FONT=Verdana][size=2][b]tell[/b] [color=#0000FF][i]application[/i][/color] "Finder" [b]to[/b] [b]set[/b] [color=#3F7F00]currentType[/color] [b]to[/b] [color=#6C04D4]name extension[/color] [b]of[/b] [color=#3F7F00]thisItem[/color]
[/size][/FONT]

herausfindest.
 
Zuletzt bearbeitet:
Ich breche zusammen...
Wahnsinn, es funktioniert.
Wo hast du nur den key code 76 "hergezogen"

Was ich jetzt noch bräuchte wäre eine Möglichkeit den Mac nach getaner Arbeit/Upload automatisch herunter zu fahren oder in den Ruhezustand zu versetzen.
Könnte das ganze dann als weiteres Script im Automator workflow dann in etwa so aussehen?
Code:
tell application "Send to Kindle"
	delay 300 -- delay in Sekunden
	quit application "Send to Kindle"
	quit application "Safari"
	tell application "Finder"
		sleep
	end tell
end tell

Die reine Funktion im Automator mit "alle Programme beenden" funktioniert leider nicht, da die Funktion sofort ausgeführt wird und nicht wartet bis der Upload beendet ist.
 
Es gibt auch eine Automatoraktion namens "Pause", damit kannst du das gleiche erreichen wie mit delay.
 
PS: Du sparst einiges an Code, wenn du die Dateiendung mit

Code:
[FONT=Verdana][size=2][b]tell[/b] [color=#0000FF][i]application[/i][/color] "Finder" [b]to[/b] [b]set[/b] [color=#3F7F00]currentType[/color] [b]to[/b] [color=#6C04D4]name extension[/color] [b]of[/b] [color=#3F7F00]thisItem[/color]
[/size][/FONT]

herausfindest.

Ich stehe da gerade auf dem Schlauch.
Könntest du bitte diese Änderung gleich in das Skript mit einpflegen und dann das komplette geänderte Script posten?
Durch die Vielzahl der supported Filetypes würde ich gerne die Option haben auch andere Dateien als pdf mit dem Script hochladen zu lassen.
Wäre diese Möglichkeit dann noch gegeben?
 
So sieht das dann aus:

Code:
[FONT=Verdana][size=2][b]on[/b] [color=#0000FF][b]run[/b][/color] {[color=#3F7F00]input[/color], [color=#3F7F00]parameters[/color]}
	[b]set[/b] [color=#3F7F00]supportedTypes[/color] [b]to[/b] {"txt", "doc", "docx", "rtf", "pdf", "png", "jpg", "jpeg", "bmp", "gif", "azw", "mobi", "prc"}
	[b]set[/b] [color=#3F7F00]numSupportedDocuments[/color] [b]to[/b] 0
	[b]repeat[/b] [b]with[/b] [color=#3F7F00]thisItem[/color] [b]in[/b] [color=#3F7F00]input[/color]
		[b]tell[/b] [color=#0000FF][i]application[/i][/color] "Finder" [b]to[/b] [b]set[/b] [color=#3F7F00]currentType[/color] [b]to[/b] [color=#6C04D4]name extension[/color] [b]of[/b] [color=#3F7F00]thisItem[/color]
		[b]if[/b] [color=#3F7F00]supportedTypes[/color] [b]contains[/b] [color=#3F7F00]currentType[/color] [b]then[/b]
			[b]set[/b] [color=#3F7F00]numSupportedDocuments[/color] [b]to[/b] ([color=#3F7F00]numSupportedDocuments[/color] + 1)
			[b]if[/b] [color=#3F7F00]numSupportedDocuments[/color] > 25 [b]then[/b]
				[b]set[/b] [color=#3F7F00]titleMsg[/color] [b]to[/b] "Send to Kindle error"
				[color=#0016B0][b]display alert[/b][/color] "Maximum of 25 supported documents can be sent at a  time." [color=#0016B0]as[/color] [color=#261151]warning[/color]
				[b]return[/b] {}
			[b]end[/b] [b]if[/b]
		[b]end[/b] [b]if[/b]
	[b]end[/b] [b]repeat[/b]
	[b]return[/b] [color=#3F7F00]input[/color]
[b]end[/b] [color=#0000FF][b]run[/b][/color][/size][/FONT]

Die Funktion sollte die gleiche bleiben.
 
Danke für die Infos.
Könnte der weitergehende und abschließende Workflow nun so aussehen?
weiterer workflow.jpg
 
Das Script zum Herunterfahren sollte sein

Code:
[FONT=Verdana][size=2][b]tell[/b] [color=#0000FF][i]application[/i][/color] "System Events" [b]to[/b] [color=#0000FF][b]shut down[/b][/color][/size][/FONT]
bzw.
Code:
[FONT=Verdana][size=2][b]tell[/b] [color=#0000FF][i]application[/i][/color] "System Events" [b]to[/b] [color=#0000FF][b]sleep[/b][/color][/size][/FONT]
wenn ich mich richtig erinnere
 
Perfekt...
Musste/habe das letzte Script nun folgendermaßen gelöst:
Code:
tell application "System Events" to tell process "Safari"
		set saf_rese to menu item 8 of menu 2 of menu bar 1 -- Menüeintrag "Safari zurücksetzen"
		click saf_rese
		click button 1 of window 1 -- es ist das Dialogfenster im Vordergrund
	end tell
	tell application "Safari" to quit
	tell application "System Events" to sleep

Der Vorteil dabei ist Send to Kindle beendigt sich nach getaner Arbeit von alleine.
Safari führt mit obigen Script nun einen "Safari zurücksetzten" aus und der Mac geht im Anschluss in den Ruhezustand oder fährt runter.
Am Anfang des gesamten Workflows habe ich nun auch noch ein Reduce File size mit eingefügt, das das Tageszeitungsfile um die hälfte der Größe eindampft.
Nun Ist es perfekt.
Ich poste gleich nochmals den Gesamten Workflow von Hazel und Automator.
 
Mein nun funktionierender Workflow um meine Tageszeitung morgens nach dem Download vollautomatisch einsortieren, umbenennen, in der File Größe verkleinern, hochladen (Amazon Kindle) zu lassen. Im Anschluß wird Safari wieder geschlossen und der MAC in den Ruhezustand versetzt bzw. bei Bedarf runtergefahren.
Als erstes Hazel und die Send to Kindle App installieren.
Dann:
Hazel Setting:
Hazel final.jpg

Automator Setting:
Workflow final.jpg

Hier der Workflow für den Automator im einzelnen:
1, Quartz Filter auf PDF Dokumente anwenden mit Filter reduce file size
2, Apple Script ausführen:
Code:
on run {input, parameters}
	set supportedTypes to {"txt", "doc", "docx", "rtf", "pdf", "png", "jpg", "jpeg", "bmp", "gif", "azw", "mobi", "prc"}
	set numSupportedDocuments to 0
	repeat with thisItem in input
		tell application "Finder" to set currentType to name extension of thisItem
		if supportedTypes contains currentType then
			set numSupportedDocuments to (numSupportedDocuments + 1)
			if numSupportedDocuments > 25 then
				set titleMsg to "Send to Kindle error"
				display alert "Maximum of 25 supported documents can be sent at a  time." as warning
				return {}
			end if
		end if
	end repeat
	return input
end run
3,Shell Script ausführen
Code:
#!/usr/bin/perl

if (@ARGV == 0) {
	exit;
}

my $args;
my $file;

$args="-cmd send -launcher shellextension";
$stkApp="/Applications/Send to Kindle/Send to Kindle.app";

foreach (@ARGV) {
    $file="$_";
    $args=$args." -file ".'"'.$file.'"'
}

system("open -n '$stkApp' --args $args");
4,Apple Script ausführen
Code:
tell application "Send to Kindle"
		activate --Programm in den Vordergrund holen
		tell application "System Events"
			tell process "SendToKindle"
				key code 76 --Enter drücken
			end tell
		end tell
	end tell
5, Pause z.B 4 Minuten
6, Apple Script ausführen
Code:
tell application "System Events" to tell process "Safari"
		set saf_rese to menu item 8 of menu 2 of menu bar 1 -- Menüeintrag "Safari zurücksetzen"
		click saf_rese
		click button 1 of window 1 -- es ist das Dialogfenster im Vordergrund
	end tell
	tell application "Safari" to quit
	tell application "System Events" to sleep

Viel Spass damit.
Die ganze Automatisierung funktioniert natürlich auch mit anderen Dateien als PDF. (Siehe Script im Punkt 2) Hazel bzw. der Automator Workflow bedürfen dazu nur kleinster Änderung z.B. Wegfall von reduce file size bei Dateien wie Doc, txt....

Namentlich möcht ich Pill und AgentMax für die Hilfe bedanken.
So, nun genug gelabert... Viel Spass damit
 
Zurück
Oben Unten