• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Der Frühling ist auch in den eingesandten Fotos deutlich zu erkennen. Zeigt uns, wer Euer Favorit ist! hier geht es lang für Euer Voting --> Klick

iCal Kalender per Script auswählen

brasax

Auralia
Registriert
11.05.10
Beiträge
199
Hi,

habe mir ein Script gebastelt um einen abonnierten Kalender zu exportieren und in den meinen Exchange-Kalender (in iCal) zu importieren. Klappt soweit ganz gut, aber leider muss ich den Kalender vorher anklicken, damit es auch funktioniert:

Code:
on menu_click(mList)
	local appName, topMenu, r
	
	-- Validate our input
	if mList's length < 3 then error "Menu list is not long enough"
	
	-- Set these variables for clarity and brevity later on
	set {appName, topMenu} to (items 1 through 2 of mList)
	set r to (items 3 through (mList's length) of mList)
	
	-- This overly-long line calls the menu_recurse function with
	-- two arguments: r, and a reference to the top-level menu
	tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
		(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
	local f, r
	
	-- `f` = first item, `r` = rest of items
	set f to item 1 of mList
	if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
	
	-- either actually click the menu item, or recurse again
	tell application "System Events"
		if mList's length is 1 then
			click parentObject's menu item f
		else
			my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
		end if
	end tell
end menu_click_recurse

tell application "iCal" to activate
menu_click({"iCal", "Ablage", "Exportieren …", "Exportieren …"})
tell application "System Events"
	keystroke return
end tell
tell application "iCal" to activate
menu_click({"iCal", "Ablage", "Importieren …", "Importieren …"})
tell application "System Events"
	keystroke return
	keystroke "RTM.ics"
	keystroke return
	delay 1
	keystroke return
	delay 1
	keystroke return
end tell

Wie kann ich im Script einen Kalender auswählen zum Export?

Jemand eine Idee?

Danke im Voraus!

brasax
 

hubionmac

Tydemans Early Worcester
Registriert
25.06.04
Beiträge
393
Ich habe die Aktion mal mit etwas weniger GUI-Scripting abgebildet.
Das Skript ermittelt alle abonnierten (nicht beschreibbaren) Kalender, fragt den einen gewünschten ab,
sucht sich über einen kleinen WorkAround die URL des Kalenders, lädt diesen selber noch einmal nach
und erst dann wird er in iCal importiert und das GUI-Scripting-Finale legt los

Code:
tell application "iCal"
	activate
	##wähle eine Kalender aus und ermittle seine UID
	## dies ist auch der Ordnername im ~/Library/Calendars in dem die plist mit
	## der URL des Kalenders liegt
	set callist to (name of every calendar whose writable is false)
	set callist2 to (name of every calendar whose writable is true)
	set callToExport to (choose from list callist default items (item 1 of callist) with prompt "Exportiere…:")
	set callToImport to (choose from list callist2 default items (item 1 of callist2) with prompt "Importiere in…:")
	if callToExport is not false and callToImport is not false then
		set callUID to uid of calendar (callToExport as text)
		##nun die URL des Kalenders auslesen
		set myurl to (do shell script "defaults read ~/Library/Calendars/" & callUID & ".calendar/Info SubscriptionURL")
		if myurl starts with "webcal" then
			set myurl to "http" & (characters 7 through -1 of myurl) as text
		end if
		##sollte ein kennwort für den Download notwendig sein:
		## set myusername to "username"
		## set mypassword to "geheim"
		## set myurl to "http://" & myusername & ":" & mypassword & "@" & (characters 8 through -1 of myurl) as text
		
		#####
		do shell script "cd /tmp;curl " & myurl & " > " & quoted form of (callToExport as text) & ".ics;open " & quoted form of (callToExport as text) & ".ics"
		delay 1
		activate application "iCal"
		tell application "System Events"
			tell process "iCal"
				click pop up button 1 of window "Ereignisse hinzufügen"
				keystroke (callToImport as text)
				delay 0.25
				keystroke return
				delay 0.25
				keystroke return
			end tell
		end tell
	end if
end tell