VSCode: is it possible to create a command that will fill a file with text on creation? - visual-studio-code

At my place of work, we have a standard source header. I've been using snippets to generate it when adding text to a file. However, since it's supposed to be pretty much used on everything, I figure I might as well see if I can automate its generation on file creation.
Is there a way to automatically add text to a file on creation in vscode? Can I generate different text based on the file extension?

Related

Is it possible to build a LibreOffice document from code similar to the way a web page is built from HTML and CSS?

Is it possible to build a LibreOffice document from code similar to the way a web page is built from HTML and CSS? Can one write an ODF file in which the content and styling are separate, and then/view open in LibreOffice? If so, can one write the code in a text editor as done for HTML/CSS?
There area two reasons I now ask. 1) When I need to make a style change in LibreOffice I have to manually make the same adjustments in a hundred places, such as changing the style of block quotes. 2) I'd like to build documents from a database of text.
I found a question on this in relation to databases but it was about eight years old.
Thank you for any direction you may be able to provide.
Unzip an .odt file that contains styles. You will see two files, content.xml and styles.xml. Edit these files using a text editor and then zip the folder back up to get a modified .odt file.
Be aware that there are two types of styles in the XML files. Named styles are what most people think of as styles, whereas automatic styles are custom formatting, like when you select some text and change the font directly.
The link from tohuwawohu describes utilities to work programmatically with the file. Also as mentioned in the link, it's not too hard to write code yourself. For example in python, import the built-in libraries zipfile and xml.etree.

Visio .vsdx format unzip and zip corrupts

I'm attempting to modify a Visio file (Open XML format) without having to use the Windows Visio application. My first experiment is just to use 7zip to unzip a known good .vsdx file that was created using Visio. That is all good; I can view the content of the package. Without making any modifications, I use 7zip to re-zip the content and renamed to .vsdx, but when I tried to open the resulting new file using Visio, it complains that the file is corrupt. Is there a way to manually re-zip the content into something that Visio accepts as a valid Visio file? I suspect that there may be some sort of checks for the validity of the file, but can't find what that may be. Thanks for any input.
I would use some form of OpenXML library to get at the file's guts using some sort of "approved magic".
Understanding that you might not want to do whatever you're doing via programming, I looked for some sort of free editor.
I found this free plug-in for Visual Studio:
https://marketplace.visualstudio.com/items?itemName=bsivanov.OpenXMLPackageEditorforVisualStudio
It works in the free "Microsoft Visual Studio Community 2019" as well. I just opened the dev environment (aka: the application) and dragged a Visio .vsdx file into the app. It opened with a tree-like editor. I was able to dig down until I found the visio > pages > page1.xml "leaf". Inside there, I was able to change some text on a shape, then save the "package".
Whatever this tool does, it saves the file properly, and I was able to open the altered .vsdx file in Visio. And the text that I changed in the editor was indeed changed inside of Visio!
I think I've used this in the past:
"Welcome to the Open XML SDK 2.5 for Office"
https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk
https://github.com/OfficeDev/Open-XML-SDK
To edit Visio files without the Visio application, you'll still need to understand how Visio works, to some extent.
A simple example:
I changed the text on a shape fairly easily within one of the page.xml files. That was easy. Then I wanted to add a copy of that shape. It was simple enough to copy and paste the whole xml block for the existing shape, then change the PinX and PinY attributes to move the shape to a different location on the page.
But you won't see that shape unless you give it a unique ID within the page. I tested deleting the ID attribute (to see if Visio would figure it out on open and assign one automatically), but it didn't work. If the ID is the same as another shape, the shape is ignored when you open the file. Once I changed ID to something unused, I did see the new copy of the shape.
If you create grouped shapes, or shapes that have advanced behavior (SmartShapes, ShapeSheet formulas, etc.), then this could get complicated. As formulas need to reference other shapes by ID, so you need to manage the IDs! For simple boxes and lines, etc., it might work well (and fast) to generate these things via OpenXML. Good luck!

How to create an extension command similar to VSCode's File: New File command?

I want to create a command that has the same flow where once you create the command it will take you to the explorer window and allow you to type the name of the file there. Is there a way to do that with the existing vscode API?
Update: The flow of creating the file through the explorer was done by executing 'explorer.newFile'. I want to take the user's input, create 2 template files, and then delete the original file created by 'explorer.newFile'. It does not seem like 'explorer.newFile' returns info about the new file so I created a filewatcher to do this which makes for choppy creation/deletion of the files. Is there a way to make this smoother?
No, not as VSCode 1.15. Your best bet currently is to either try reusing the built-in create file command (explorer.newFile) or to use the quick picker API to achieve a similar flow

How to generate t3d file automatically?

I am trying to create a data.t3d file for my TYPO3 sitepackage.
How can I generate this file based on my custom configuration automatically without usind the wizard every time?
I am using TYPO3 8.7.2
Thanks
First of all the most important question: How often do you generate this file? Please note that this is no backup! In most cases you create your sitepackage, export the file and place it in the Initialisation directory. So there is no need to do it often.
One solution to have the same settings for every export (which is more useful I think) is to create a "Preset".
How to create a preset?
You can create a preset when opening the import/export-module and changing to the "File & Preset"-Tab.
Enter a title for your preset and click "Save".
How to load a preset?
To load a preset you select the preset in the "File & Preset"-Tab and press "Load".
Hopefully this will help you.

Powershell [Add-Content/Write-Host] : Adding a hyperlink to plain text

I have written a Powershell script to perform some actions:
Read a .xls file
Compile certain .c files
Copy output files.
I log everything performed by the script to a Log file (e.g. output.log)
I later invoke a tool which performs an analysis of the actions performed by the script and writes them into an Excel sheet.
I would also like to write the path of the excel sheet inside output.log and also provide a hyperlink to it but I have not been able to do so.
Example:
Currently the link to the excel sheet is written as file://\\10.128.163.188\d\abc.xls, but I would like to have a hyperlink to it.
Can you please suggest how to do that?
p.s. I am not working with HTML Docs / UI (i found many examples for the same), but for adding a hyperlink into a plain text written inside a .txt file, i couldn't find any.
You cannot add hyperlinks to a plaintext document. It does not have that functionality.
It has to be a rich text file (.rtf), or a Microsoft Word Document (.doc), or a HTML file.
There is no way around this.