Jump to content

[SOLVED] return json and copy results to clipboard in Javascript


Recommended Posts

Hello,everybody! I write a javascript in alfred workflow, try to return the json and copy the result to clipboard at the same time. Could anybody tell me how to make it?Thanks~

function run(argv) {
  var temp = argv[0];
  var num;
  num = temp * 1000;
  return JSON.stringify({items: [
      {title: "The number is :",
       subtitle:num
      }
    ]})
  //return num;//It dosn't work.
}

image.png.18712780ad7812dc026fa3bce421fcc2.pngimage.png.aadb5115cb61b4440442609ecc61a003.png

Link to post
2 hours ago, DickDi said:

return JSON.stringify({items: [ {title: "The number is :", subtitle:num } ]})

//return num;//It dosn't work.

 

You can't use multiple returns like that: once a return statement is executed, the function has finished.

 

Have a look at the Script Filter documentation and the example workflows built into Alfred.


If you want to pass num back to Alfred, you have to put it in the item's arg property.

return JSON.stringify({items: [
	{title: "The number is :",
	 subtitle: num,
	 arg: num   // <-- here
  	}
]})

 

Link to post
2 hours ago, deanishe said:

 

You can't use multiple returns like that: once a return statement is executed, the function has finished.

 

Have a look at the Script Filter documentation and the example workflows built into Alfred.


If you want to pass num back to Alfred, you have to put it in the item's arg property.


return JSON.stringify({items: [
	{title: "The number is :",
	 subtitle: num,
	 arg: num   // <-- here
  	}
]})

 

Thanks so much! I reckon that I should study hard about workflow.😁😁

Link to post
  • vitor changed the title to [SOLVED] return json and copy results to clipboard in Javascript

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...