Hammerspoon fails to run Javascript that runs fine in Script Editor - macos

I'm trying to get today's events from Calendar.app in Hammerspoon.
I have the following Javascript, that works well in the Script Editor:
But, if I paste this in a call to hs.osascript.javascript(), like this:
local source = [[
var Calendar = Application("Calendar")
var startDate = new Date
startDate = startDate
startDate.setHours(0)
startDate.setMinutes(0)
startDate.setSeconds(0)
var endDate = new Date
endDate.setHours(23)
endDate.setMinutes(59)
endDate.setSeconds(59)
var projectCalendars = Calendar.calendars.whose({name: "MyCal"})
var projectCalendar = projectCalendars[0]
var events = projectCalendar.events.whose({startDate: {_greaterThan: startDate}, endDate: {_lessThanEquals: endDate}})
var event = events[0]
event().summary()
]]
print("yyy", hs.osascript._osascript(source, "JavaScript"))
This produces the following error:
yyy false nil {
NSLocalizedDescription = "Error: Error: An error occurred.";
NSLocalizedFailureReason = "Error: Error: An error occurred.";
OSAScriptErrorBriefMessageKey = "Error: Error: An error occurred.";
OSAScriptErrorMessageKey = "Error: Error: An error occurred.";
OSAScriptErrorNumberKey = "-1743";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
Using hs.osascript.javascript produces the same behavior.
I'm not sure what I'm doing wrong here. Can someone advise please? I'm running Big Sur.

Related

Showing Syntax error, unexpected variable “$buyValue”

Showing Syntax error, unexpected variable “$buyValue”
I don't know where I mistake on livewire controller, anyone please help to findout where I mistake here.
$marketData = \Http::get('https://api.binance.com/api/v3/ticker/24hr?symbol='.$lists->pair.'USDT')->json()
$buyValue = $lists->size * $lists->entry_price;
$currentvalue = $lists->size*$marketData['lastPrice'];
$profitloss = $currentvalue - $buyValue;
if($price > $lists->entry_price){
if($lists->order_type == "buy") {
$lists->profit_loss = $profitloss;
}else{
$lists->profit_loss = '-'.$profitloss;
}else{
if($lists->order_type == "buy") {
$profit_loss = $profitloss;
}else{
$profit_loss = substr($profitloss, 1);
}
}
`
Please help
you have missed semicolon ( ; ) at the end of very first line in script you posted.
$marketData = \Http::get('https://api.binance.com/api/v3/ticker/24hr?symbol='.$lists->pair.'USDT')->json()
to
$marketData = \Http::get('https://api.binance.com/api/v3/ticker/24hr?symbol='.$lists->pair.'USDT')->json();

ServiceNow - Data Transform Script Debug

I am using a data transform to import a large .csv of emails into a Watchlist field. My .csv is in the following format:
"ipsum#test.com", "ipsum#test.com, lorem#test.com",,"ipsum#tests.com"
I am using the following script to link the imported emails to User records, however my data transform ignores all records despite me manually confirming the emails exist, is there something wrong in this script?
answer = (function transformEntry(source) {
var grUsers = new GlideRecord('sys_user');
var users = String(source.u__users).split(",");
var query = 'email=LIKE' + String(users[0]);
var i = 1;
while(i != users.length){
query = query + '^ORemailLIKE' + String(users[i]);
i++;
}
grUsers.addEncodedQuery(query);
grUsers.query();
return grUsers.join(',');
})(source);
Two problems:
Using split(",") is not enough if the format you are showing is correct. You need to strip the quotes as well
Using email=LIKE should be emailLIKE, no = sign
Here is an example based on your data:
var data = '"alpha#test.com","beta#test.com","lorem#test.com","ipsum#tests.com"';
var users = String(data).split(",");
for (var i = 0; i < users.length; i++){
gs.print(users[i])
}
var query = 'email=LIKE' + String(users[0]);
gs.print(query);
Running this in Background Scripts I get:
*** Script: "alpha#test.com"
*** Script: "beta#test.com"
*** Script: "lorem#test.com"
*** Script: "ipsum#tests.com"
*** Script: email=LIKE"alpha#test.com"
Here's the fixed one:
var data = '"alpha#test.com","beta#test.com","lorem#test.com","ipsum#tests.com"';
var users = String(data).split(",");
for (var i = 0; i < users.length; i++){
users[i] = users[i].replace(/^"(.*)"$/, '$1');
}
for (var i = 0; i < users.length; i++){
gs.print(users[i])
}
var query = 'emailLIKE' + String(users[0]);
gs.print(query);
Result:
*** Script: alpha#test.com
*** Script: beta#test.com
*** Script: lorem#test.com
*** Script: ipsum#tests.com
*** Script: emailLIKEalpha#test.com

Getting below error while running ruby script

I am running a test suite in Soap UI where I am trying to call one ruby script from groovy script. The step is getting executed successfully but still the script is not able to move on to the next step as it gives this error after running.
Have searched in google about this error, but found no proper resolution. Moreover the error itself is not very explanatory.
Will appreciate any kind of help.
Below is the groovy script which is calling "ap-v4-batch_DEV_QA.rb" ruby script.
This ruby script opens a browser and performs the task successfully and closes the browser. We expect the step to be marked as Passed so that it can move on to the next step, but it gives the error mentioned at the bottom.
Groovy Script:
String script = "webdriver/v4/ap-v4-batch_DEV_QA.rb";
String argv0 = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("GLOB_DefaultIP");
String argv1 = "com.wupay.batch.process.tasks.PaymentFileParsingTask_RunOnce";
String argv2 = "";
String argv3 = "";
String argv4 = "";
/* Nothing needs to be modified below */
String commandLine = "ruby " + com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("GLOB_ScriptLocation") + "/" + script + " " + argv0 + " " + argv1 + " " + argv2 + " " + argv3 + " " + argv4;
log.info("Running command line: " + commandLine);
java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
java.lang.Process p = runtime.exec(commandLine);
def propertyStep = testRunner.testCase.getTestStepByName("Properties");
java.io.BufferedReader stdInput =
new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
java.io.BufferedReader stdError =
new java.io.BufferedReader(new java.io.InputStreamReader(p.getErrorStream()));
String s = null;
String e = null;
StringBuffer eb = new StringBuffer();
while ((e = stdError.readLine()) != null) {
eb.append(e);
log.error("Ruby: " + e);
}
while ((s = stdInput.readLine()) != null) {
log.info("Ruby: " + s);
if(s.startsWith("#prop")) {
String[] propSplit = s.split(":", 3);
testRunner.testCase.setPropertyValue(propSplit[1], propSplit[2]);
}
}
p.waitFor();
log.info("Ruby: exit value " + p.exitValue());
if(eb.length() > 0) {
throw new Exception(eb.toString());
}
Error:
java.lang.Exception: C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in require':require "watir-webdriver"is deprecated. Please, userequire "watir". java.lang.Exception: C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:inrequire': require "watir-webdriver" is deprecated. Please, use require "watir". error at line: 57
I have finally resolved the issue.
The issue was that ruby script was not accepting require "watir-webdriver".
I installed watir and replaced require "watir-webdriver" with require "watir".
now I am not getting the above mentioned error.
Thanks anyways!
Regards,
Faraz

Error System.Runtime.InteropServices.COMException

I got a problem with a project I'm making
it's program that gets signature from a wacom
sign pad It works fine at first run then whenever
I try to enter another signature for the second
time it gets this error message
Here is the code:
Dim sigCtl As New SigCtl
Dim dc As New DynamicCapture
Dim res As DynamicCaptureResult
sigCtl.Licence = "AgAZAPZTkH0EBVdhY29tClNESyBTYW1wbGUBAoECA2UA"
res = dc.Capture(sigCtl, "who", "why", vbNull, vbNull)
If (res = DynamicCaptureResult.DynCaptOK) Then
print("signature captured successfully")
Dim sigObj As SigObj
sigObj = sigCtl.Signature
sigObj.ExtraData("AdditionalData") = "VB test: Additional data"
Dim filename As New String("sig1.png")
sigObj.RenderBitmap(filename, 200, 150, "image/png", 0.5F, &HFF0000, &HFFFFFF, -1.0F, -1.0F, _
RBFlags.RenderOutputFilename Or RBFlags.RenderColor32BPP Or RBFlags.RenderEncodeData)
sigImage.Load(filename)
Else
print("Signature capture error res=" & res)
Select Case res
Case DynamicCaptureResult.DynCaptCancel
print("signature cancelled")
Case DynamicCaptureResult.DynCaptError
print("no capture service available")
Case DynamicCaptureResult.DynCaptPadError
print("signing device error")
Case Else
print("Unexpected error code ")
End Select
End If
The error occurs around sigobj.rederbitmap syntax it gives of the System.Runtime.InteropServices.COMException exception
I'm kinda puzzled whats wrong here since it always work at first try
Thanks in advance*strong text*
I had the same problem with a wacom STU-530 device.
What worked for me was to change the filename string each time the user wanted to use another test.
Dim rndm As New Random
Dim serial As Integer = rndm.Next(1, 9999)
Dim str_serial As String = CStr(serial)
Dim filename As New String("sig_" & str_serial.PadLeft(4, "0") & ".png")

Mac querytables

I have written a script which downloads data from yahoo finance into excel using querytable. It should loop through each URL and download the data but it can't get past the second loop and fails at the .Refresh BackroundQuery:=False with the error code 1004 - An unexpected error has occurred.
Here is the code:
rowOffset = 0
url = Worksheets("Yahoo codes").Range("b2").Offset(rowOffset, 0)
Do While url <> ""
With ActiveSheet.QueryTables.Add(Connection:="URL;" & url, Destination:=Worksheets("Yahoo Data").Range("A65536").End(xlUp).Offset(1, 0))
.RefreshStyle = xlOverwriteCells
.SaveData = True
.BackgroundQuery = True
.Refresh BackgroundQuery:=False
'.Refresh
End With
rowOffset = rowOffset + 1
url = Worksheets("Yahoo Data").Range("a2").Offset(rowOffset, 0)
Loop
It looks like you get the first URL from B2 and subsequent URLs from A3...
When you get the error, got to the Immediate Window (Ctl+G) and type
?Worksheets("Yahoo Data").QueryTables(2).Connection
and see if it looks right. If not, I suspect your second url = ... statement is wrong.

Resources