Jump to content

start applescript, display notification with Alfred, continue applescript


Recommended Posts

I want to use Alfred notification for displaying data that I got using AppleScript. So the workflow basically gathers an information using an AppleScript, returns that information back to Alfred wich should display a notification and then the AppleScript should continue or another AppleScript should start, which should get the variables of the first AppleScript. 

The reason for this is that I cannot figure out how to use custom icons in notifications within AppleScript. I wanted to use Alfred for this, since I can configure notifications how I want. So the goal is to return information from an AppleScript back to Alfred, Alfred is displaying those information and continues the AppleScript. Is this possible?

Link to comment

Hello @WalterBeiter,

 

We can’t properly help you without access to your Workflow.


Debugging can already be hard with access to the code, and you’re asking us to guess yours from a description. There are multiple places where you code or Workflow setup may be going wrong. Without looking at it we’re shooting in the dark, which is a waste of time for everyone involved (including you).


Read the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report.

 


 

6 minutes ago, WalterBeiter said:

The reason for this is that I cannot figure out how to use custom icons in notifications within AppleScript.

 

You can’t from an AppleScript script — a notification with a custom icon needs to come from an app. Take a look at notificator (disclaimer: I’m the author) for a quick way to make such apps. I use it in my own Workflows.

 

8 minutes ago, WalterBeiter said:

So the goal is to return information from an AppleScript back to Alfred, Alfred is displaying those information and continues the AppleScript. Is this possible?

 

Yes. The simplest way is to not have it in succession. There’s no apparent reason why the next step would need to come only after the notification has fired. Instead, make two connections:

7G3bSU9.png

Link to comment
29 minutes ago, vitor said:

We can’t properly help you without access to your Workflow.

→ The workflow does not exist yet, I am still developing the AppleScript but I ran into the problem of not knowing how to display custom notifications with a custom icon. So I though I would just do this using Alfreds notifications...

Sorry for not providing enough details. I thou they would distract from the main problem. 

 

 

Quote

You can’t from an AppleScript script — a notification with a custom icon needs to come from an app. Take a look at notificator (disclaimer: I’m the author) for a quick way to make such apps. I use it in my own Workflows.

→ notificator could work. I installed it, but it requires me to first run that setup, saving that app somewhere and then call it again. This would be a lot of file handling which is not that nice... Where do you store the icon, the app,.. etc.

Not quite sure how I would implement this into an AppleScript. I know I could launch notificator with the do shell script command, but how do I bundle the custom notificator app with the script? I want to use this with every Mac. 

 

 

Quote

Yes. The simplest way is to not have it in succession. There’s no apparent reason why the next step would need to come only after the notification has fired. Instead, make two connections:

7G3bSU9.png

→ this could work, but how to I return multiple variables in AppleScript and then importing them in the second AppleScript? And how do I post a notification of just one of them? 

And it would require dividing the applescript wherever I post a notification. 

 

Edit: How do I specify a custom icon in this notification? I can't find an area where I drag and drop an icon.

 

 

 

Bottom line: If this gets to complicated, I will just give up and stick with the script editor icon. 

Edited by WalterBeiter
Link to comment

Regarding notificator, you only run the setup once: to solidify an icon and a bundle ID. It’ll save it to an app. You keep that app inside the Workflow’s directory and call it as needed. It will work on all your Macs when you share/sync the Workflow amongst them.


You cannot set your own icon with Alfred’s notification; if you could, notificator would not exist. A notification needs to use the icon of the app that calls it.


If you want to return multiple variables, you’ll need to either return a JSON in the same format as the JSON Utility or you’ll do it like in other languages: returning everything in your own format and then parsing it yourself. I would recommend against AppleScript, though. Unless it’s absolutely necessary, doing complex tasks with it is more pain than it is worth.

Link to comment
31 minutes ago, vitor said:

Regarding notificator, you only run the setup once: to solidify an icon and a bundle ID. It’ll save it to an app. You keep that app inside the Workflow’s directory and call it as needed. It will work on all your Macs when you share/sync the Workflow amongst them.

→ maybe I'll try that. 

 

31 minutes ago, vitor said:

If you want to return multiple variables, you’ll need to either return a JSON in the same format as the JSON Utility or you’ll do it like in other languages: returning everything in your own format and then parsing it yourself. I would recommend against AppleScript, though. Unless it’s absolutely necessary, doing complex tasks with it is more pain than it is worth.

→ AppleScript is mandatory for what I'll try to accomplish, so I think I will try that notificator thing. If that does not work or get to complex, I will skip this part and use the standard icons. But having the script editor icon show up whatever notification is displayed is annoying, especially when scripting multiple applications. 

 

Thanks for all the quick help. 

Link to comment
2 hours ago, WalterBeiter said:

AppleScript is mandatory for what I'll try to accomplish

 

Are you sure you can't use JXA instead? JavaScript supports JSON.


If not, just because you have to use AppleScript for parts of your workflow, doesn't mean you have to use it for everything. Apart from a couple of loonies, who appear to actually like AppleScript, most workflow developers use the absolute minimum amount of AS, and do the rest in a sane language.

Link to comment
  • 4 years later...
On 12/20/2017 at 11:24 AM, vitor said:

Regarding notificator, you only run the setup once: to solidify an icon and a bundle ID. It’ll save it to an app. You keep that app inside the Workflow’s directory and call it as needed. It will work on all your Macs when you share/sync the Workflow amongst them.


You cannot set your own icon with Alfred’s notification; if you could, notificator would not exist. A notification needs to use the icon of the app that calls it.

 

Hi @vitor - I recently came across your Notificator app, and it looks awesome! I had been looking for a cleaner way of handling workflow notifications, and your app looks like it will do a great job.

 

To that end, I have a couple of minor questions that I was hoping to bounce off you, regarding its use:

 

1 - Is it possible for the Notificator to use different icons/images from a workflow (assuming this is even possible in MacOS - i.e., that apps' notifications can display different icons from their defaults)?

 

I didn't see an option in the command where users could tell the app which icon to use (like a file path or name to an image inside the workflow's directory), but I thought I'd ask. From what I understand, the first time you call the app, it automatically pulls its icon from the default one in the workflow. Then, once the app is built, it will only use that specific icon (i.e., unless you rebuild it, and the workflow's default icon is different at the time that it's rebuilt). 

 

2 - Assuming that's correct, is it possible to add more than one Notificator to a workflow, and assign each a different icon?

 

In other words, if each Notificator app always has to display the same icon, could you get around this limitation by simply adding more than one of them to the workflow? Obviously, this would require there to be some way for users to tell the Notificator, when it's first built, which icon/image for it to use (i.e., otherwise, even if you could add more than one to a workflow, they would both pull the workflow's default icon when built - defeating the purpose of having more than one in a workflow).

 

3 - Is it possible for users to specify a different app name for the Notificator (i.e., on setup or something, so that you see that name instead of "Notificator" in System Preferences > Notifications & Focus > Notifications)?

 

Sorry for all of the questions @vitor. Regardless, the Notificator looks amazing! You rock!!!

Link to comment
6 minutes ago, Jasondm007 said:

your Notificator app

 

Worth noting it is now just a script, thought it used to be an app. It has gotten a major overhaul since the conversation in this thread. It used to be more generic and do some of what you ask but it required a setup process. Since realistically I only used it for Alfred (and that was always the motivation), I removed the configuration so it can just be “download and use”.


With that in mind, your requests are technically possible but out of scope. Though the whole thing is a single short script with comments so you can edit it to your needs.

 

16 minutes ago, Jasondm007 said:

1 - Is it possible for the Notificator to use different icons/images from a workflow (assuming this is even possible in MacOS - i.e., that apps' notifications can display different icons from their defaults)?

 

To display a different icon you need to build a different app. That’s essentially what the script does, it creates the app which is then invoked.

 

18 minutes ago, Jasondm007 said:

Then, once the app is built, it will only use that specific icon (i.e., unless you rebuild it, and the workflow's default icon is different at the time that it's rebuilt). 

 

It is auto-rebuilt if it’s older than 30 days when called, so a changed icon is eventually renewed.

 

19 minutes ago, Jasondm007 said:

2 - Assuming that's correct, is it possible to add more than one Notificator to a workflow, and assign each a different icon?

 

Yes, by making several copies of the script and changing the constants under # Check for required arguments to something else.

 

20 minutes ago, Jasondm007 said:

3 - Is it possible for users to specify a different app name for the Notificator

 

Same as above, by changing the app’s name. This one I will change the default, to name apps as Notification for WORKFLOW_NAME.app. Should make them easier to identify in Preferences. I’d like to keep “Notificator” at the start so they’re all together and easy to find.

 

Pinging @xilopaint for the Python3 library inclusion. Just pushed the change.

 

36 minutes ago, Jasondm007 said:

Regardless, the Notificator looks amazing! You rock!!!

 

Thank you for the kind words!

Link to comment

@vitor Thanks a ton for the thoughtful and detailed response above. This is super helpful!

 

I hate to admit it, but I didn't realize that it was even possible to edit the executable. I'll take a look at everything, and see if I can figure out which constants need to be modified when using multiple scripts in a workflow (to avoid overwriting things, etc.).

 

Thanks a ton! I'm looking forward to tinkering with this one (and ... think Notificator should have been included in Alfred 5 ;)

Link to comment
  • 2 weeks later...
1 minute ago, Jasondm007 said:

what is the "Python3 library inclusion"?

 

@xilopaint is building a Python3 library for workflows. One of the things it allows you is to call a notification with the workflow’s icon. Which is exactly what notificator does, so that’s what the library uses—it includes the full script. I was letting @xilopaint know I made an update, so the library could be updated to ship the latest version (which is the one I support).

Link to comment
1 minute ago, vitor said:

 

@xilopaint is building a Python3 library for workflows. One of the things it allows you is to call a notification with the workflow’s icon. Which is exactly what notificator does, so that’s what the library uses—it includes the full script. I was letting @xilopaint know I made an update, so the library could be updated to ship the latest version (which is the one I support).

 

Got it! Thanks!!

Link to comment

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...