Mail Rules with javascript instead of applescript - javascript

In a Mac mail rule, I am trying to run a javascript instead of an applescript. This has been asked in Mail Rules using JavaScript for Automation instead of AppleScript but the answer is not working for me!
I have tried to simplify the code as much as I can. So, the following applescript works fine:
on perform mail action with messages theMessages
say "running!"
end perform mail action with messages
but the equivalent javascript is not working.
function performMailActionWithMessages(messages) {
app = Application.currentApplication()
app.includeStandardAdditions = true
app.say ("running")
}
Edit
Here are my rule parameters

I do it without getting app. Try something like…
// ObjC.import('Cocoa')
ObjC.import('stdlib')
var program="/usr/bin/say"
function performMailActionWithMessages(messages) {
say("running")
}
function say(what){
var command = program + " '"+what+"'"
console.log(command)
$.system(command)
}
I’m not sure you need cocoa. You probably need stdlib.

Related

Making a simple ASP webpage that displays updating values from C# program

I have never used ASP.NET before and I don't quite understand how the MVC system works, but my application is much more simple than the tutorials provided.
I have a webpage in HTML, and I currently have a C# program that gets key presses from my keyboard (Making a webpage that displays key presses). Both of these work, and the C# program prints to the terminal.
I can't however, seem to connect the two, by making a web page that has data bindings so that whenever a C# class updates, it changes the HTML content without page refresh.
This would probably require learning a lot, but I'm hoping to make it with a few files (maybe a controller isn't needed since the page has no interaction?). I'm not sure how to even make a DOTNET project, as the sample one has many built-in pages and routes that I don't understand.
So basically, this is my C# program (with DLL in the same dir)
using System;
using WootingAnalogSDKNET;
// We'll also include this for the Thread.Sleep call we'll have later on
using System.Threading;
using System;
using System.IO;
using System.Net;
using System.Threading;
Console.WriteLine("Hello Analog SDK!");
// Initialise the SDK
var (noDevices, error) = WootingAnalogSDK.Initialise();
// If the number of devices is at least 0 it indicates the initialisation was successful
if (noDevices >= 0) {
Console.WriteLine($"Analog SDK Successfully initialised with {noDevices} devices!");
}
else {
Console.WriteLine($"Analog SDK failed to initialise: {error}");
System.Environment.Exit(1);
}
while (true) {
var (keys, readErr) = WootingAnalogSDK.ReadFullBuffer(20);
if (readErr == WootingAnalogResult.Ok)
{
// Go through all the keys that were read and output them
foreach (var analog in keys)
{
Console.Write($"({analog.Item1},{analog.Item2})");
}
// We want to put on the new line character only if keys have been read and output to the console
if (keys.Count > 0)
Console.WriteLine();
}
else
{
Console.WriteLine($"Read failed with {readErr}");
// We want to put more of a delay in when we get an error as we don't want to spam the log with the errors
Thread.Sleep(1000);
}
// We want to have a bit of a delay so we don't spam the console with new values
Thread.Sleep(100);
}
Thank you in advance for you help!

add Office.onReady() function to javascript

I am new to Javascript and am trying to make an outlook web-addin take the Office.onReady() function properly.
https://learn.microsoft.com/en-us/office/dev/add-ins/develop/initialize-add-in
I tried using
Office.onReady()
.then
to make my function work with the office js API but it then I got an error that my function couldn't be found.
Code:
$("#brief-summary").click(briefsummary);
$("#email-setup").click(emailsetup);
Office.onReady()
.then(function briefsummary() {
var msgFrom = Office.context.mailbox.item.from;
var msgfirstname = String(msgFrom.displayName).split(" ");
Office.context.mailbox.item.displayReplyAllFormAsync(
"Hello " +
msgfirstname[0] +
", <br> \
<br> Here is a brief summary on everything worked on: \
<br> \
<br>Thank you for your time, \
<br>"
);
});
Result:
Uncaught ReferenceError: briefsummary is not defined
So I am pretty sure I am doing it wrong.
I also tried using Office.onReady(); at the begining of the script. It suppressed the Uncaught Error: Office.js has not fully loaded. Your app must call "Office.onReady()" error but office javascript doesn't do anything. (Its suppose to bring up a new reply window with text inside)
Link to where the app is hosted: https://alloyautomateaddinbeta3.azurewebsites.net/index.html (Although the office.js only loads when you are in the outlook app. But you can go to sources from inspector in chrome and look at the js script in full)
Any ideas would be awesome.
I have seems to figure out what to do but I was pretty janky. If anyone knowas a better way to clean this up let me know.
I essentially my code inbetween this and it worked:
Office.onReady((info) => {
if (info.host === Office.HostType.Outlook) {
#Insert code here
}
});
It was pretty janky as it gives me a warning saying Function variables should not be placed in blocks. Use a function expression or move the statement to the top of the outer function
I will be working on the code periodically so I will update my answer to a better one as time goes on unless someone else has an answer as well.
Thanks

Android Calling JavaScript functions in Button

I've an Android Activity and I've got a Button that button need to access some Javascript function. Simply my app get the user info(ID,pass) then go to web page(this operation doing backgrun with asynctask class) write these two info as ID and pass then user click the Log In button in my app button has to use some js function
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
this is the func. i need to use
My post and get request for connection the site are
POST//
URL url = new URL(params[0]); //http://login.cu.edu.tr/Login.aspx? site=https://derskayit.cu.edu.tr&ReturnUrl=%2f
connection=(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data);
writer.flush();
these codes for the put the ID and pass
GET //
reader= new BufferedReader((new InputStreamReader(connection.getInputStream())));
StringBuilder builder = new StringBuilder();
String line;
while((line= reader.readLine())!=null){
builder.append(line + "\n");
}
text=builder.toString();
there is any help or suggestion for me i am very confused about that situation and i feel really bad myself thanks for helps anyway. Have a nice day
For using Javascript without a webView to make requests!
The question has already an answer here in this question
The javax.script package is not part of the Android SDK. You can execute JavaScript in a WebView, as described here. You perhaps can use Rhino, as described here. You might also take a look at the Scripting Layer for Android project.
Also a similar question was asked here
You can execute JavaScript without a WebView. You can use AndroidJSCore. Here is a quick example how you might do it:
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://your_website_here/file.js");
HttpResponse response = client.execute(request);
String js = EntityUtils.toString(response.getEntity());
JSContext context = new JSContext();
context.evaluateScript(js);
context.evaluateScript("question.vote(0);");
However, this most likely won't work outside of a WebView, because I presume you are not only relying on JavaScript, but AJAX, which is not part of pure JavaScript. It requires a browser implementation.
Is there a reason you don't use a hidden WebView and simply inject your code?
// Create a WebView and load a page that includes your JS file
webView.evaluateJavascript("question.vote(0);", null);
Otherwise:
Yes you can make HTTP POST and HTTP GET requests without using WebView. But if you want to use a webView remember Javascript in a webview is disabled by default (for security purposes). So before calling any javascript functions make sure you enable javascript in your webview like this
webView.getSettings().setJavaScriptEnabled( true );
And after that javascript will be enabled in your webView.
But in case you do not want to use a webview and javascript to make http requests. There is a lot of alternative methods you can define a Button in your activity's layout in xml. And respond with a http request on button Clicked listener!
Also remember making http Request using Android/Java default classes is a huge task and error prone and requires you to care about using async tasks to avoid blocking the UI thread.
Alternatively
In android we use ready-made library to make http requests. Google has a good library called Volley. it is easy to customize,respond to errors and it automatically making request out of the main thread.See more explanation here!. If there is still some problems comment below!

Bookmarklet to run js

I have been trying to create a bookmarklet to run quick javascript, and am having trouble doing so. I have tried
javascript:var runjs = prompt("Enter JS:");function runjs() {runjs};
it seems you want to do the following
javascript:eval(prompt("Enter JS:"));
this will evaluate (run) the code entered in the prompt
as per comment
javascript:try{eval(prompt("Enter JS:"));}catch(e){alert(e);}
this will catch most? errors

HTML automatic site login filling. value with no parameters

The website im trying to login to has the following username field
<input type="text" id="inputEmailHandle" name="inputEmailHandle" value>
Im using Zombie Headless browser and nodejs, Zombie cannot find the input field named "inputEmailHandle" so i cannot automatically log in, i think its because of the value>
is there anyway i can get around it? or does anyone know a good way to do this with javascript and nodeJS?
ps the website im trying to log into is craigslist
Here's the code
var Browser = require("zombie");
var assert = require("assert");
browser = new Browser()
browser.visit("https://accounts.craigslist.org", function () {
browser.
fill("inputEmailHandle", "person#email.com").
fill("inputPassword", "password").
pressButton("button", function() {
console.log("LOGGED INNNNN!!!");
assert.ok(browser.success);
})
});
The website is running iso-8859-1 encoding, which is apparently not supported by zombie... that is why its not finding anything

Categories

Resources