Bash and dialog UI, how to change color dynamically - linux

I have a simple bash script, which I use to maintain some log etc files on a server, and most of the time the tools works in "normal mode". For UI I use the dialog tool.
However, sometimes I have some condition that requires more careful attention, and I would like at those times to change the background color of dialog, to draw more attention to the issue.
I know that by changing the screen_color attribute in .dialogrc, I can define custom colors for the dialogs, but that affects all windows, and is not what I want.
Is there some way to dynamically set this variable so that only specific dialogs would have different colors, and everything else unaffected?

For a given dialog process, you can select a specific configuration file using the environment variable DIALOGRC (see manual).

Related

Godot: Is there any way I can invoke a method in my Script from the editor? (for testing purposes)

I come from Unity, and there you can use ContextMenu method attribute. It will add a button in the editor you can click and the method in your script will be invoked.
This is very helpful for testing/debugging purposes. When you are testing a functionality and you want an easy way to trigger it.
Is there something similar in Godot, or any workaround I can use?
(Godot 3.5 here)
There are multiple ways to run code in the editor.
In fact, Godot games and the Godot editor are built on the same core. One way to say is that Godot is build on Godot… But a more accurate way to say it is that your games are Godot without the editor, plus whatever you built on top.
As a consequence, you have a lot of freedom when extending the Godot editor.
For starters you will be making a tool script. To do that you the tool keyword on the top of the script file. This allows the script to run in the editor.
Warning: Remember that in Godot the Game is not running inside the Editor. Anything that your script moves while running in the Editor would be a modification to the project, for good or ill. And it does not come with build-in undo functionality. It is possible to add undo functionality (with the UndoRedo class), but that is also something you would have to program.
By the way, you might want to know if your code is running on the editor or not. For that, you can check Engine.editor_hint which will be true in the editor.
Read more on the article Running code in the editor.
Since the tool script modify the project. What I present below is more often used to setup parts of the scene or to automate parts of the development workflow. Not for testing features. However since the linked documentation about ContextMenu mentions that it is useful for…
automatically setting up Scene data from the script
I believe what present below is not out of place.
With that said, some modifications of the editor are harder than others. I believe you don't really want to go into the trouble of adding a button to the editor (which is perfectly possible) or an option to the menus (which is also possible, but not everywhere, at least not easily). Instead, I'll stay with the easy options for this answer:
You can make an EditorScript. That is a script that extends the EditorScript class and overrides the _run method. For example:
tool
extends EditorScript
func _run():
print("Hello from the Godot Editor!")
To execute it, have it open in the Script Editor, and to the File menu, and select Run. You can also use secondary click on the script on the "Scripts Panel (on the left of the Script Editor) and select Run in the contextual menu.
The drawback is that is script does not work in the game. It is only for the editor.
Although Godot 3.x does not have official (there is a plugin) support for inspector actions (it might land in Godot 4), we can workaround that. What we will do is export a bool property, and handle (with a setter, which we specify with setget) what happens when you set it. Like this:
tool
extends Node # or whatever
export var do_something:bool setget on_do_something
func on_do_something(_mod_value:bool) -> void:
# do whatever you want
pass
The property should show up as a checkbox in the Inspector panel when the node is selected. And clicking the checkbox will trigger the setter method on_do_something… Which will do whatever you want it to do. Notice also that I'm discarding the value that Godot is trying to set to the property (_mod_value) so it will remain false.
This pattern has got popularity among Godot developers.
If you want to add elements to the Godot UI you would have to make an EditorPlugin (see the Editor Plugins section in the documentation).
Alright but, since the tool script could cause modifications to the project, which might be a problem for testing… What do we do for testing?
Well, I will remind you that you can tell Godot to execute specific scenes (it does not have to run the main scene), and that can another way to test your code.
Furthermore, when your game is running you can go to the Scene panel and select the Remote tab to see the Nodes that exist in the game. Which will allow you to select them, which shows their properties in the Inspector, which would be able to modify (having an effect in real time on the executing game).
… And thus something similar to what I described above about using a setter would work. Except it does not need the tool keyword since it won't be running in the editor:
# No tool
extends Node # or whatever
export var do_something:bool setget on_do_something
func on_do_something(_mod_value:bool) -> void:
# do whatever you want
pass
By the way, in the inspector, when the game is executing and you have the relevant Node selected, you will see your property twice. The first one will trigger the setter, while the second one bypasses it. So pay attention which one you are using.
You might also be interested in the "Project Camera Override" feature, which allows you to freely move the game camera from the editor. You access the feature via the top bar in the editor.
You will also find that it is possible to modify Resources in the editor and see the effect in real time while the game is running. And a Script is a Resource… However pause the game from the Debugger panel (or use a breakpoint) and make sure the script you want to modify is not being executed before you modify it.

Sublime Text plugin development: modifying the Quick Panel to add a custom text title or label?

I'm developing a Sublime Text 3 plugin which uses the quick panel a.k.a. the command palette.
I would like to add a textual title/label at the top of the quick panel when the user opens my plugin's quick panel menu, because my plugin runs in various modes and I want to make it clear which mode is currently running (Test, Pre-Live, Live, etc.)
Is this possible, and how?
This a mockup of what I want to achieve:
This is not possible in a quick panel, no. The only thing you can provide to the quick panel display-wise is the list of items that you want the user to choose from. Each item in the list can contain multiple lines of data however (with the restriction that every row has to contain the same number of lines):
Something like that could potentially be used to provide context on the items in the list that allows the user to know what mode you're in.
The Command Palette and the quick panel aren't the same thing (although they are visually similar); the command palette only displays commands that you can choose. By using an input handler, you can customize the display somewhat:
In this sample, View Package File is the selected command, but the command has control over what that text says (it's just the command name by default). You also have the power to provide a "preview" (basically any extra information that you want) about the currently selected item:
So given that, depending on your use case your command could present its interface in the command palette to give this kind of contextual clue.

applescript display dialog with custom icon

Is there a way to use custom icons with applescript display dialog and notifications?
In the AppleScript documentation it says about the display dialog:
with icon (text | integer)
The resource name or ID of the icon to
display.
with icon (stop | note | caution) The type of icon to show.
You may specify one of the following constants:
stop (or 0): Shows a stop icon
note (or 1): Shows the application icon
caution (or 2): Shows a warning icon, badged with the application icon
with icon (alias | file) An alias or file specifier that specifies a .icns file.
So it seams like you can use your own icons, but I cannot get the following code to work.
display dialog "Text" with icon "/Users/user/Desktop/asd.icns"
It gets me the following error: "Resource not found."
The goal is to not even use a display dialog, but a display notification instead.
First of all you can't display a custom icon with display notification. The reason is that notifications are strongly related to a target application. As AppleScript scripts and applets aren't applications in terms of the Notification framework, the notification is related to the current application, the AppleScript Runner.
But you can display a custom icon with display dialog
The line
with icon (alias | file) An alias or file specifier that specifies a .icns file.
means what it says: The parameter must be an alias or file specifier rather than a POSIX or HFS string path.
Either
display dialog "Text" with icon alias ((path to desktop as text) & "asd.icns")
or
display dialog "Text" with icon file ((path to desktop as text) & "asd.icns")
path to desktop as text represents the HFS path to the desktop of the current user:
"Macintosh HD:Users:user:Desktop:"
Noted this question was three years ago, but I stumbled across this looking for a solution to a similar problem. Mine needs display alert rather than ... notification but the problem is the same because display alert doesn't have a custom icon option.
As noted in the other answer here, AppleScript has at least three interactive message type commands: display dialog, display alert, display notification, and probably others. It seems odd that only the first has the option to add a custom icon. I don't really understand why that is when it would be simple to make them consistent.
Needless to say, this question and #vadian's answer, inspired my solution - a "duh" moment for me once I realized it. It may or may not be a solution to this question. Posting it in case it is...
If the icon in question belongs to an app, you can tell that app to display the notification, regardless of whatever else your script is doing.
Your script can do whatever it needs to do to whatever other apps, or System Events, or itself (if your script is saved as its own application), or whatever else. In the middle of all of that you can have a single line that says:
tell application "MyApp" to display notification ...
The notification will have My App's icon, the result of the notification if any will be returned to the rest of the script and then your script will continue on inside whatever other tell statement or context its in.
If your icon isn't the icon for an app, then I believe there are ways to create an empty app with whatever icon you like, which can behave this way. Admittedly that's a bit of a kludge, but depending on how badly you want this, it's an option - though not one I'll expand on here.
My specific case in detail if interested (but doesn't particularly add to the solution above, just covers how I got there):
I'm writing a script that quits and re-opens another application after confirmation from the user. However, let's say I just wanted to provide a notification as per this question.
Options:
1. display dialog - has the option to provide a custom icon but lacks features of the other two options.
2. display alert - no custom icon but has other desired features, in my case the message parameter which adds extra smaller explanatory text below the primary text.
3. display notification - no custom icon but has other features as desired by this question's poster.
In my case I want alert because I want that extra message parameter (but this works for notification as well).
In my case, ideally the icon of the alert would be the icon of the app I'm restarting, but I can't tell the app itself to display the alert and then restart because the script loses connection with the app when it quits and it kills the running of the script.
If I tell System Events or the script itself to do all that then it can quit and reopen the app independently of the app, but the alert has the generic icon of itself or the System Events icon.
However, if I do what I described above - have my script do all its stuff, but have it tell the app in question to display the alert (and only that as described above), then the alert has the icon of the app in question, but the script still does its stuff independently of the app outside of that alert.
Solved my problem. May or may not solve this question.
#DavidT's answer is a perfect solution when your script is controlled by another application. However, things have changed a bit on Mac OS since.
Notably, if you run your script with tell application "MyApp" to display alert ... you will be promoting the user to give your app permissions to control itself, at least starting since Catalina. Not only this annoys the user with a new permission request, but it also looks kinda dumb since the dialogue is asking the user to allow "MyApp" to control "MyApp" and if the user denies it, your script will fail.
To avoid the permission request, just use tell me to display alert ... this will work just fine.
Another issue you might run into is that osascript may throw an exception if your script is launched as root. I found a nice workaround for that here.
This is a small example of how to launch the dialogue with the right user:
uid=determineUserIdFunction(...)
launchctl asuser $uid /usr/bin/osascript <<-EOS
tell me to display dialog "Now you see me" buttons {"OK"} default button 1 with title "WARNING!"
EOS
You have your path specification wrong. If you have a posix path to your icns file, use the POSIX file class coercion:
display dialog "Text" with icon POSIX file "/Users/user/Desktop/asd.icns"
This coerces the string path into a file reference the system understands, and works just fine.

Can menus in Vim be made "dynamic"?

i.e. to show a value (let's say, for the purpose of this example, set tabstop? ... 8), but when that value changes to show the changed value?
I'm playing with Vim to see if I could setup a menu which would display some of my more used settings to save up on set setting? ... any ideas?
I also find it a little bit unusual to put settings values into the menu (a menu item usually is associated with an action that is triggered by selecting it), and would also recommend using either the 'statusline' (for settings that you want to see in parallel for each open buffer) or 'titlestring' (for settings that you only need for the current buffer).
You can use the :menu and :unmenu command to dynamically create and update menu items. Unlike the above mentioned mechanisms, however, Vim will not automatically trigger the updates; you have to do this with :autocmds on the appropriate events (e.g. CursorHold) yourself.

Notepad++ tab color

Is there a way to change the color of a tab (in the tab bar) according to the path of the file?
I tried with the PythonScript plugin, but couldn't find a method to change the color of a tab.
I need this because I edit scripts from two environments at the same time, from a LIVE environment, and from a development environment, and I need to be extra careful when editing a LIVE file.
I was looking for a programmatic way to change the color of the tabs, and reviewed the online documentation of Notepad++ but did not find anything about it. So, instead, I propose the following method for your case, it could be helpful to always know which of your files are from the development environment and which from the live environment:
Open a blank instance of Notepad++:
Now start a macro recording: Press Start Recording button on Notepad++ toolbar:
Open a new document
Now you'll have two open blank tabs.
Right click newly open tab and click in option Move to other view from contextual menu
You'll have a window splitted vertically and your two tabs will be displayed next to each other. You'll use these two tabs as separated "containers" for your files
Press Stop Recording button:
Save your just recorded macro:
assign a keyboard shortcut:
Now you can run that recorded macro (from Macro menu, or invoking keyboard shortcut you assigned), every time you want to work on your two environments.
(Optional) Right click vertical separator between "containers" and click Rotate to right
Now your "containers" will be split horizontally and will be displayed one above the other. Personally, I'd recommend you this layout.
Click on the tab at first "container" and from there, open all your "dev" environment files; and analogously open all your "live" environment files from second "container". Note that currently selected container has a more intensely coloured active tab.
If you notice that your working space is small, drag the separator to increase your current "container" size, but I recommend you not to take it completely towards the end, because it will make difficult to differentiate which of the two "containers" you are working on.
Note: If you, mistakenly opened a file of an environment from the wrong "container" you'll always be able to fix that by dragging the tab and dropping it to the other "container":
So you'll always keep control of what files must be on each container.
That's it. I hope this info will be helpful for you.
About changing the color of the tab (not folder specific).
Notepad++ has a file called stylers.xml, located in the roaming folder or in the program folder. It also depends in the installation & windows version. If it does not exists then it is self generated.
At the very end of the file, it says
<WidgetStyle name="Inactive tabs" styleID="0" fgColor="xxxxx" bgColor="xxxxxx" />
And here it is possible to change the color of the inactive tab.
However, it does not work, it is a bug that has been "fixed" countless of times in the past. To the date, the current version 6.2.3 UNICODE, changing the values does nothing.
So far, editing the stylers.xml:
6.2.3 = does nothing
design guideline, gray + gray = not good.
6.2.0 = does nothing
6.1.8 = works.
Nice contrast
6.1 = works.
5.9.8 = works.
5.7 = edit works.
ps: sadly,it is not possible to change the fonts of the tabs.
Wanted to add this as a comment, the button's not there.
You can solve your actual problem by using multiple instances of notepad++, refer this. You can save different sessions and optionally use the "Open File In Solution (OFIS)" plug-in.
I've if you've picked a different Style like 'Black Board', then you will have to change these setting in it's .XML in '/themes', and these setting are found at the bottom of the file.

Resources