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 comment
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 comment
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 comment
  • vitor changed the title to [SOLVED] return json and copy results to clipboard in Javascript

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...