Setting up a function to tag scripts for notifications
5 次查看(过去 30 天)
显示 更早的评论
I have a simple notification setup that is using pbNotify from FileExchange, which sends a notification to my mobile phone via Pushbullet when a long-running script finishes. For the setup to work, I have to add a line with my token and another line containing my message. I also generally pass the elapsed time with tic-toc command couple to the message (it is really convenient!).
Now, I do not want to include the two lines of code in my scripts and comment/uncomment occasionally. I want to prepare a function that does this work "semi-automatically".
Say that I have a script called "work.m", running time of which depends on the amount of data I input. Whenever I know that the script will take a long time to process the data, I will come to the Command Window and call my script, say that it is "add_notification.m". When I call add_notification.m , the work.m script's notifications will be turned on and when I run work.m, I will always get notifications upon completion until I toggle it off. Note that I do not add anything on work.m.
I have some ideas for this to work. For example, I can get an active (in editor) script's path with:
matlab.desktop.editor.getActiveFilename
I can use this with add_notification.m to prepare some kind of a "name pool", including the names of the scripts that I want notifications from. Then, I need to find a way to check if work.m has completed processing without adding anything into it manually. If work.m has completed, then another script, say it is called "notificate.m" runs automatically and checks if the completed script's name is included in the name pool. If the name is in the list, then I get a notification, if not, nothing happens.
Do you have any ideas? Is this possible?
I can also simplify my question into these sub-questions:
- Is it possible to "programmatically" check if a script have completed running?
- ...if it is possible, then how can I run another script right after to get notifications?
0 个评论
采纳的回答
Dinesh
2024-2-1
Hi Nedim,
To achieve your goal of receiving notifications without modifying your original script, you can wrap the execution of "work.m" within another function, "add_notification.m", which will execute "work.m" and upon completion, check against a list of scripts set for notification and trigger "notificate.m" if there’s a match. You can use MATLAB's "evalin" function to run "work.m" within the base workspace from "add_notification.m", and then use "onCleanup" to ensure "notificate.m" is called after "work.m" completes.
The following links might help you:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!