2

I have a script to run from a command line prompt. The command, followed by some text, will set a reminder in the Reminder.app with a due date of next friday. The script is taking about 100 seconds to run which seem very high.

on nextWeekday(wd)
    set today to current date
    set twd to weekday of today
    if twd is wd then
        set d to 7
    else
        set d to (7 + (wd - twd)) mod 7
    end if
    return today + (d * days)
end nextWeekday

on run argv
    set nextFriday to nextWeekday(Friday)
    tell application "Reminders"

        set newLable to argv as string

        set myList to list "Do."

        tell myList
            set newReminder to make new reminder
            set name of newReminder to newLable
            #set remind me date of newReminder to theDay
            set allday due date of newReminder to nextFriday
        end tell
    end tell
end run

The code in the .bash_profile is as follows:

function reme() {
  cd
  cd /Users/jamieauburn/Documents/projects/reminder
  osax reme.scpt $1
}

Have I got something wrong in the script?

Zohaib Amir
  • 3,482
  • 2
  • 11
  • 29
JAuburn
  • 21
  • 2

1 Answers1

0

You have a lot of unnecessary things here. Your script can be written much more compactly, and it becomes about 4 times faster.

on run argv
    tell (current date) to set nextFriday to it + (6 - (its weekday)) * days
    tell application "Reminders" to tell list "Do."
        make new reminder with properties {name:(argv as string), allday due date:nextFriday}
    end tell
end run
Robert Kniazidis
  • 1,760
  • 1
  • 7
  • 8