How do I add an iCal event using JS automation in OS X Yosemite? - macos

I'm really having a hard time understanding how to interact with iCal using the new support for Javascript automation in Yosemite. I'm not too experienced with OOP so that might be where my problem lies.
Could someone help me out with the code for adding a new event to a specified calendar? I can probably reverse engineer it from there to understand how to work with it.
Thanks
UPDATE
Here is the code I am trying..
// -- perform adding to iCal
// -- select "Test" calendar
theCalendar = iCal.calendars.Test;
events = theCalendar.events;
// -- load in the events
stringifiedData = Safari.doJavaScript("localStorage.getItem('theEvents');", {
in: Safari.windows[0].tabs[0]})
// -- parse data back to js object
theEvents = JSON.parse(stringifiedData);
// -- loop through events
for (var key in theEvents) {
var obj = theEvents[key];
// -- set vars
theDate = obj['date'];
theDescription = obj['description'];
theSummary = obj['summary'];
theLocation = obj['location'];
theStartTime = theDate + " " + obj['startTime'];
theEndTime = theDate + " " + obj['endTime'];
// -- create event object
theEvent = iCal.Event({
description: theDescription,
summary: theSummary,
location: theLocation,
startDate: theStartTime,
endDate: theEndTime
});
// -- get the last index event
last = events.length;
// -- insert it into iCal
events.push(theEvent);
}
The error i'm receiving..
Error on line 68: TypeError: undefined is not an object (evaluating 'events.push(theEvent)')
UPDATE
I figured out the issue. I was formatting the dates incorrectly.. they were just strings. So I made sure to turn them into date objects, and I was able to insert successfully using
events[last] = theEvent;

Related

How do I export contents between xml tags based on names in Extendscript for Indesign?

All I'd like to do here is open an InDesign 2018 CC file, pull out text uniquely (here I've chosen to grab content inside XML tag called "Title" from named tag window in the InDesign application side), save it to a txt file, and close the InDesign doc. I'm working in the Extendscript app, using Adobe InDesign CC 2018 (13.064). I just need to push to a txt file only certain named data (textboxes, xmltags, pageitems, etc) the contents based on anything, but via the name of the data holder. But xmltags are the only objects that I can name in the InDesign app apart from layers, and layers won't work for other reasons. So I'm stuck not being able to refer to xml-tagged contents. Please help.
Note:
I get an error with this code saying "Title" isn't defined, and I understand the error, but not sure how to utilize the method XML.toString() without referring to an object that's named inside the InDesign file. So I guess I'm using the wrong method to refer to xml-tagged data already located in a file??
So naturally, I throw out XML.toString() and utilize the commented out code (below) "app.activeDocument.xmlItems.item;" thinking maybe I will get an array of all items that are xml tagged, which is not even specific enough for my goal, but I'm desperate, and I get another newer error regarding the "exportfile" line of code: myArticles.exportFile() is not a function.
My code so far:
app.open(File("C:/Users/Sean/Desktop/New folder/va tech 2.indd"), true);
myArticles = Title.toString();
//THIS ATTEMPT WON'T WORK EITHER AS RPLCMNT FOR LINE ABOVE: myArticles= app.activeDocument.xmlItems.item;
myArticles.exportFile(ExportFormat.textType, new File("/C/Users/Sean/Desktop/New folder/test.txt"), false);
app.documents.everyItem().close(SaveOptions.NO);
var main = function() {
var doc, root, xes, n, nXE, st, xc, strs = [],
f = File ( Folder.desktop+"/contents.txt" );
try {
//NEED TO CHANGE THE URL. Ex: some/url > /Users/user/Desktop/foo.indd
doc = app.open ( File ( "some/url" ) );
}
catch(err){
alert(err.message);
return;
}
if ( !doc ) {
alert("You need an open document" );
return;
}
root = doc.xmlElements[0];
xes = root.evaluateXPathExpression("//Title");
n = xes.length;
while ( n-- ) {
nXE = xes[n];
xc = nXE.xmlContent;
if ( xc instanceof Story ) {
strs.push( xc.contents );
}
}
if ( strs.length ) {
f.open('w');
f.write ( strs.reverse().join("\r") );
f.close();
}
}
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

Parse Cloud "beforeSave" not saving data

I'm using parse beforeSave method to save an order, here is the code:
//Before save an order - if finish - set priority to 0
Parse.Cloud.beforeSave("UserToOrders", function(request, response) {
Parse.Cloud.useMasterKey();
var preStatus = request.object.get("OrderStatus");
if (preStatus == "Finish") {
request.object.set("Priority",0);
console.log("beforeSave(\"UserToOrders\")\t Order (" + request.object.id + ") Status is 'Finish' So Priority set to '0'");
}
else {
console.log("beforeSave(\"UserToOrders\")\t Order (" + request.object.id + ") Status Changed to: " + preStatus);
request.object.set("OrderStatus",preStatus);
}
response.success();
});
Here is the log:
I2016-03-09T20:56:05.779Z]v136 before_save triggered for UserToOrders for user pSi0iCGJJe:
Input: {"original":{"ACL":{"*":{"read":true},"vxgEWFQ7eu":{"read":true,"write":true}},"OrderStatus":"Ready","OrderStatusActivity":"Active","ResturantID":"g1bzMQEXoj","TimeToBeReady":{"__type":"Date","iso":"2016-03-08T23:35:23.916Z"},"UserETA":{"__type":"Date","iso":"2016-03-08T23:35:23.916Z"},"UserID":"vxgEWFQ7eu","createdAt":"2016-03-08T21:06:06.605Z","objectId":"t3NoxcSp5z","updatedAt":"2016-03-08T21:40:59.538Z"},"update":{"OrderStatus":"Finish","objectId":"t3NoxcSp5z"}}
Result: Update changed to {"OrderStatus":"Finish","Priority":0}
I2016-03-09T20:56:05.975Z]beforeSave("UserToOrders") Order (t3NoxcSp5z) Status is 'Finish' So Priority set to '0'
but nothing is being changed in the DB.
What do i miss?
Thanks.
in var preStatus is the same value as you wanted to save...
var preStatus = request.object.get("OrderStatus");
and you are "saving" the same value, you can just delete this line
request.object.set("OrderStatus",preStatus);
if it is not what you want, provide the log from "OrderStatus" = Finish
I've figured it out. It was an ACL permissions issue.
The Order created by one client, while the chance made by another one.

Pushing Offline Leads using Adwords API

I am using the below function to push my offline leads to api, everything looks good and returns success but when I check adwords, it doesnt show any data saying it received. I have tried many leads and also waited for around 3-4 days now.
What am I doing wrong?
function UploadOfflineConversionsExample(AdWordsUser $user, $conversionName,$gClId, $conversionTime, $conversionValue)
{
// Get the services, which loads the required classes.
// $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION);
$offlineConversionService = $user->GetService('OfflineConversionFeedService', ADWORDS_VERSION);
// Associate offline conversions with the upload conversion we created.
$feed = new OfflineConversionFeed();
$feed->conversionName = $conversionName;
$feed->conversionTime = $conversionTime;
$feed->conversionValue = $conversionValue;
$feed->googleClickId = $gClId;
$offlineConversionOperation = new OfflineConversionFeedOperation();
$offlineConversionOperation->operator = 'ADD';
$offlineConversionOperation->operand = $feed;
$offlineConversionOperations = array($offlineConversionOperation);
$result = $offlineConversionService->mutate($offlineConversionOperations);
$feed = $result->value[0];
return ("Uploaded offline conversion value of ". $feed->conversionValue.
" for Google Click ID = ". $feed->googleClickId." and Conversion Name " . $feed->conversionName);
}
In adwords reports this conversion will be shown in Conversions Column. and change the daterange to the date what you pushed as $conversionTime

VWAttachment added through API is not showing in CM 5.2

I have retrieved a workitem using API and changed the attachment fields using setParameterValue , After saving the work usingstepElement.doSave(true), I can see the added attachments in the process tracker through process administration console , but my problem is it is not showing up in case navigator and in workplaceXT also it is saying "Attachment may be corrupted or deleted"
below is the code i used to create attachment
tempAtt.setAttachmentName("check.png");
tempAtt.setAttachmentDescription("Added by code");
tempAtt.setType(VWAttachmentType.ATTACHMENT_TYPE_DOCUMENT);
tempAtt.setLibraryType(VWLibraryType.LIBRARY_TYPE_CONTENT_ENGINE);
tempAtt.setLibraryName("TOS");
tempAtt.setId(doc.getVersionSeries().getId());
tempAttA[0] = tempAtt;
stepElement.setParameterValue("Zip", tempAttA, true);
I dont understand where i am wrong , please suggest.
//Filenet p8 5.2 , Content Platform Engine
Got the solution after banging my head for a couple of hours , posting the entire code , may be helpful for others
//Connect to PE
//Query the queue with wobnum and get the workobject
queryIndex = "F_WobNum";
queryMin[0] = wob;
queryMax[0] = wob;
queryFlag = VWQueue.QUERY_MIN_VALUES_INCLUSIVE + VWQueue.QUERY_MAX_VALUES_INCLUSIVE;
queryType = VWFetchType.FETCH_TYPE_WORKOBJECT;
queryTypeStepElement = VWFetchType.FETCH_TYPE_STEP_ELEMENT;
queue = session.getQueue("Queue_Name");
query = queue.createQuery(queryIndex, queryMin, queryMax, queryFlag, null, null, queryType);
System.out.println("count " + query.fetchCount());
workObject = (VWWorkObject) query.next();
//get the stepelement
stepElement = workObject.fetchStepElement();
parameters = stepElement.getParameters(VWFieldType.ALL_FIELD_TYPES, VWStepElement.FIELD_USER_AND_SYSTEM_DEFINED);
//get the existing attachment value
tempAttA= (VWAttachment[]) stepElement.getParameterValue("attachment_field_name");
//attachment is VWAttachment array
attachment=tempAttA;
//lock the item for working
stepElement.doLock(true);
//set the new values for the new attachment to be added
tempAtt=new VWAttachment();
tempAtt.setAttachmentName("Attachment_name");
tempAtt.setAttachmentDescription("Added by code");
tempAtt.setType(VWAttachmentType.ATTACHMENT_TYPE_DOCUMENT);
tempAtt.setLibraryType(VWLibraryType.LIBRARY_TYPE_CONTENT_ENGINE);
tempAtt.setLibraryName("TOS");
//vs id of the existing CE document , note that adding attachment means refering a CE object , so the document u want to attach should be stored in CE before.
tempAtt.setId(doc.getVersionSeries().getId());
attachment=tempAttA;
//law is a arraylist of VWAttachment type , so u dont override any existing attachments
law.add(attachment[0]);
law.add(tempAtt);
//set the attchment field with new values
stepElement.setParameterValue("attachment_name", law.toArray(), true);

How to handle Reminder that are old and new for windows phone

say, this is the way to create reminder:
Reminder reminder = new Reminder(name);
reminder.Title = titleTextBox.Text;
reminder.Content = contentTextBox.Text;
reminder.BeginTime = beginTime;
reminder.ExpirationTime = expirationTime;
reminder.RecurrenceType = recurrence;
reminder.NavigationUri = navigationUri;
// Register the reminder with the system.
ScheduledActionService.Add(reminder);
I can not see the result as I use emulator and I have these questions:
1) If I create a reminder today 25/Jul : Begin time 25-jul and ExpirationTime : 25-jul, after 25-jul, will the reminder created on 25-jul will still be in the system or scheduler?
2) If the expirationTime is 28-Jul, will it shows the BeginTime when this reminder got activated on 28-jul?
3) How to I retrieve all the reminders have not be activated.
Thanks
--- Updated :
var reminders = ScheduledActionService.GetActions (ScheduledAction)();
.Where(a => a.IsScheduled);
1) Yes, it will be there. Reminders associated with an application are still available, even if those are dismissed by the user.
2) The BeginTime will be set according to the class property that is set by the application, not when the reminder was activated.
3) You can retrieve all reminders registered for your application through:
var n = ScheduledActionService.GetActions<Reminder>();
foreach (Reminder r in n)
// Action here
You can check the IsScheduled property to make sure that the reminder is scheduled to be triggered or is already out of the queue.

Resources