Hello!
I have a script I want to work with. The idea is that you can highlight text, for example in the mail, and then run a script to add the text into the calendar. It would be best if you could have a scroll bar that you could choose the date and time, but I have read that it is not possible in AppleScript if you do not mix in Xcode, and I’m not ready for that yet. So, therefore, I wonder how to do it if you want, for example, that after I create the event in iCal, iCal opens up automatically the event I create. So, then, the procedure shall be as follows.
Select some text
Select services
The user input on what it wants to rename the event to
The highlighted text is pasted as a description …
So far everything is okay … But how do I do if I want Ical to open the actual event automatically so the user can make fine adjustments such as time, etc.?
Here’s an example in Calendar. I think it should work in iCal.
tell application "Calendar"
launch
activate
set home_cal to first calendar whose name is "Home"
set new_event to make new event at home_cal with properties {summary:"Some Title", description:"Some Description"}
show new_event
end tell
tell application "System Events" to keystroke "i" using command down
You can look at the dictionary of iCal for more properties to set.
Here’s another approach. Step 1: copy selected mail text to clipboard. Step 2: create event using copied text as the event summary (name). Step 3: open the newly created event so it can be edited as you wish.
tell application "Mail"
activate
tell application "System Events"
keystroke "c" using {command down}
end tell
set theEventName to the clipboard
end tell
tell application "Calendar"
activate
set thecalendars to every calendar
set theName to name of item 1 of thecalendars --change item to correct calendar
set theDate to the current date
tell calendar theName
set theEvent to make new event at end with properties {summary:theEventName, start date:theDate, allday event:true}
end tell
show theEvent
tell application "System Events"
keystroke "e" using {command down}
end tell
end tell
thanks to you both. I did a combination of your two suggestions, and was the ideal solution, which is not only bound to the e-mail application. Thank you!
with this solution I can use it with any text
on run {input, parameters}
set topic to text returned of (display dialog “Choose subject for event” default answer “” & input buttons {“Make it”} default button 1)
tell application “Calendar”
activate
tell calendar “Work”
set theDate to (current date) + 2 * days
set eventName to topic
set theEvent to make new event at end with properties {description:input, summary:topic, location:“Event Location”, start date:theDate, allday event:true}
end tell
tell calendar "Arbete"
show theEvent
tell application "System Events"
keystroke "e" using {command down}
end tell
end tell
end tell
return input