View Single Post
Originally Posted by uku View Post
(These are the first apple scripts I ever wrote, so I think the script codes aren't very smart. Perhaps someone could help me to optimize these scripts?)
Clever and handy! I like them.

I've rewritten your "Task to iCal" script. It's gone from 126 lines of code to 50. :) I took out unnecessary intermediate variables, converted all the variables holding parts of the highlighted task into a record, and un-nested the redundant "if" statements in the "iCal" section.

I think a fair argument could be made that changing this
	set theNewTask to the name of theSelectedTask
	set theNewNote to the note of theSelectedTask
	set theNewDueDate to due date of theSelectedTask
	set hasFlag to flagged of theSelectedTask
into this
set newTask to {name:name, TaskNote:note, TaskDueDate:due date, IsFlagged:flagged} of theSelectedTask
isn't inherently an improvement, since it means that later on, this
if theNewDueDate is not missing value then
		if TaskDueDate of newTask is not missing value then
but the reason I did that was it makes it much easier to create a list of new tasks, so you could highlight multiple tasks in the context window, invoke the script, and have all of them transferred to iCal at once.

I even wrote the code to collect multiple tasks. I did not rewrite the second half of my replacement script to install the multiple tasks: it will only do the first one. Why? Because I've already frittered away more than a couple hours on this, and I'm supposed to be doing other stuff. I might get back to it; you might finish the job before I do and repost it, thus saving me the effort. :)

I didn't look at your second script, but I hope you can see various tricks and techniques from this script that you could apply there as well.
Attached Files
File Type: zip new Task to (7.2 KB, 451 views)