Package util.misc

Examples of util.misc.AppleScriptRunner


      return;
    }
    final String title = mParser.analyse(settings.getTitle(), program);
    final String desc = mParser.analyse(settings.getDescription(), program);
    if (OperatingSystem.isMacOs()) {
      final AppleScriptRunner runner = new AppleScriptRunner();
      final String script = "tell application \"GrowlHelperApp\"\n"
          + "   set the allNotificationsList to {\"TVBrowserSendProgram\"}\n"
          + "   register as application \"TV-Browser\" all notifications allNotificationsList default notifications allNotificationsList icon of application \"TV-Browser\"\n"
          + "   notify with name \"TVBrowserSendProgram\" title \""
          + runner.formatTextAsParam(title) + "\" description \""
          + runner.formatTextAsParam(desc)
          + "\" application name \"TV-Browser\"\n" + "end tell";
      try {
        runner.executeScript(script);
      } catch (IOException e) {
        mLog.log(Level.SEVERE, "Can't execute AppleScript\n\n" + script, e);
      }
    } else {
      final Notification notification = new Notification(mApplication,
View Full Code Here


    public String getName() {
        return "Apple iCal";
    }

    public boolean exportPrograms(Program[] programs, CalendarExportSettings settings, AbstractPluginProgramFormating formatting) {
        AppleScriptRunner runner = new AppleScriptRunner();

        StringBuilder script = new StringBuilder();

        SimpleDateFormat formatDay = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatHour = new SimpleDateFormat("HH:mm");

        String calTitle = settings.getExporterProperty(AppleiCalExporter.PROPERTY_CALENDAR_NAME);
        if (StringUtils.isBlank(calTitle)) {
          calTitle = "TV-Browser";
        }
        script.append("property myTVCalendar : \"" + calTitle + "\"\n");

        script.append("on stringToList from theString for myDelimiters\n" +
          "\ttell AppleScript\n" +
          "\t\tset theSavedDelimiters to AppleScript's text item delimiters\n" +
          "\t\tset text item delimiters to myDelimiters\n" +
          "\t\t\n" +
          "\t\tset outList to text items of theString\n" +
          "\t\tset text item delimiters to theSavedDelimiters\n" +
          "\t\t\n" +
          "\t\treturn outList\n" +
          "\tend tell\n" +
          "end stringToList\n" +
          "\n" +
          "\n" +
          "on getDateForISOdate(theISODate, theISOTime)\n" +
          "\tlocal myDate\n" +
          "\t-- converts an ISO format (YYYY-MM-DD) and time to a date object\n" +
          "\tset monthConstants to {January, February, March, April, May, June, July, August, September, October, November, December}\n" +
          "\t\n" +
          "\tset theISODate to (stringToList from (theISODate) for \"-\")\n" +
          "\tset theISOTime to (stringToList from (theISOTime) for \":\")\n" +
          "\t\n" +
          "\tset myDate to current date\n" +
          "\tset month of myDate to 1\n" +
          "\t\n" +
          "\ttell theISODate\n" +
          "\t\tset year of myDate to item 1\n" +
          "\t\tset day of myDate to item 3\n" +
          "\t\tset month of myDate to item (item 2) of monthConstants\n" +
          "\tend tell\n" +
          "\ttell theISOTime\n" +
          "\t\tset hours of myDate to item 1\n" +
          "\t\tset minutes of myDate to item 2\n" +
          "\t\tset seconds of myDate to 0\n" +
          "\tend tell\n" +
          "\t\n" +
          "\treturn myDate\n" +
          "end getDateForISOdate\n" +
          "\n");

        script.append("\n");
        script.append("tell application \"iCal\"\n");
        script.append("  if (exists (calendars whose title is myTVCalendar)) then\n");
        script.append("    set TVBrowserCalendar to first item of (calendars whose title is myTVCalendar)\n");
        script.append("  else\n");
        script.append("    set TVBrowserCalendar to make new calendar with properties {title:myTVCalendar}\n");
        script.append("  end if\n");
        script.append("\n");

        for (Program program : programs) {
            final Calendar start = CalendarToolbox.getStartAsCalendar(program);
            final Calendar end   = CalendarToolbox.getEndAsCalendar(program);

            script.append("  set startDate to my getDateForISOdate(\"").append(formatDay.format(start.getTime())).append("\", \"").append(formatHour.format(start.getTime())).append("\")\n");
            script.append("  set endDate to my getDateForISOdate(\"").append(formatDay.format(end.getTime())).append("\", \"").append(formatHour.format(end.getTime())).append("\")\n");
            script.append("\n");
            script.append("  set props to {start date:startDate, end date:endDate, summary:\"");

            ParamParser parser = new ParamParser();

            String title = parser.analyse(formatting.getTitleValue(), program);
            script.append(title);

            script.append("\", description:\"");

            String desc = parser.analyse(formatting.getContentValue(), program);
            script.append(desc.replaceAll("\"", "\\\\\"").replace('\n', ' '));

            script.append("\"}\n");
            script.append("  set theEvent to make new event at end of (events of TVBrowserCalendar) with properties props\n");

            if (settings.getUseAlarm()) {
                script.append("  make new display alarm at beginning of theEvent with properties {trigger interval:-");
                script.append(settings.getAlarmMinutes());
                script.append("}\n");
            }

        }

        script.append("end tell\n");

        try {
            runner.executeScript(script.toString());
        } catch (IOException e) {
            e.printStackTrace();
            ErrorHandler.handle("Error during execution of the applescript", e);
        }
View Full Code Here

TOP

Related Classes of util.misc.AppleScriptRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.