Hammerspoon: Unparsed output from applescript

Created on 22 Aug 2016  Â·  10Comments  Â·  Source: Hammerspoon/hammerspoon

I'm not sure that I understand what I should be seeing, but:

screen shot 2016-08-22 at 1 00 39 pm

I want to get the value that I entered ("face"), but there is nothing in y. I figured that I can resort to using a regex to pull the entered value out, but this seems like a bug to me.

bug enhancement

All 10 comments

Agreed, this is not very sensible!

FWIW, I did a little tweaking to NSAppleEventDescriptor+Parsing.m and the following change, intuited from what I found at http://stackoverflow.com/a/13182999:

+(NSDictionary*)scriptingUserDefinedRecordWithDescriptor:(NSAppleEventDescriptor*)desc {
    NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:0];

    // keyASUserRecordFields has a list of alternating keys and values
//     NSAppleEventDescriptor* userFieldItems = [desc descriptorForKeyword:keyASUserRecordFields]; // <-- original line
    NSAppleEventDescriptor* userFieldItems = desc ; // <-- added this line
    NSInteger numItems = [userFieldItems numberOfItems];

Results in an output for y of:

> hs.inspect(y)
{
    OK = "what I typed"
}

But I hesitate to upload the change without testing/comment from @heptal, since (a) I don't use AppleScript much myself, so I don't know what other uses of the reco DescType this might break, and (b) I don't know enough about NSAppleEventDescriptor objects to know when the original line would/should work or how we might be able to tell the difference.

_EDIT: typo in original source code posted._

+1 getting some feedback from @heptal. I very rarely use the responses from Applescript, so if this works, and hs.itunes works, I would not know what else to test!

I'm a newbie to Hammerspoon, so I could be completely wrong, however, I feel like it actually works as expected. Here's an example of how I would write the code:

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "t", function()
     ok,appleScriptResult = hs.osascript.applescript([[  
        set dialogBox to (display dialog "tell me something" default answer "")
        return the text returned of dialogBox
     ]])     
     hs.alert.show(appleScriptResult)   
end)

I think your AppleScript is better than mine :)

Sent from my iPhone

On Sep 19, 2016, at 1:11 AM, Chris Hocking [email protected] wrote:

I'm a newbie to Hammerspoon, so I could be completely wrong, however, I feel like it actually works as expected. Here's an example of how I would write the code:

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "t", function()
ok,appleScriptResult = hs.osascript.applescript([[
set dialogBox to (display dialog "tell me something" default answer "")
return the text returned of dialogBox
]])
hs.alert.show(appleScriptResult)
end)

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@cmsj - I reckon you can close this issue unless @joelmccracken disagrees?

I agree, this seems fine to me.

@cmsj - FYI: This issue can be closed.

@cmsj & @asmagill - Just a friendly reminder that we can close this issue.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fent picture fent  Â·  3Comments

iliyang picture iliyang  Â·  4Comments

latenitefilms picture latenitefilms  Â·  4Comments

latenitefilms picture latenitefilms  Â·  3Comments

agzam picture agzam  Â·  3Comments