Hooking into "Sublime Text has finished loading" event - sublimetext

Is there an API call to determine if Sublime Text has finished loading, including reopening all files that were open before Sublime was closed last? Maybe there is something similar to plugin_loaded(), which gets called after the plugin has finished loading?
If this is not possible, are the files that were open last listed somewhere?

I am not sure if there is such API. However, you can get all stored buffers in file Sublime Text 2\Settings\Session.sublime_session (search "buffers" in it).

Related

how to skip content block in wordpad

I writing a code in vb.net. The codes will create a .rtf (wordpad file format). in that code i'm not only write text but a picture as well. the problem is windows always ask content security everytime i add a picture (fyi, picture already exist in my computer) into that file.
this is the preview
i tried to find setting in windows and wordpad, but still got nothing
how can i skip this security warning?
thank you
Just to clarify, I'm seeing the same issue. RTF created by hand by myself, new text with a few URLs, and pasted images captured by Windows screenshot grabbing app.
Dir /r was showing no alternate stream, but I still got the annoying message box every time I open the file.
Turns out the blocked content were the images, they also won't get copied to the clipboard. Tried grabbing them again, and pasting them to Paint and back to the document, and now WordPad likes them.

Windows - Opening a file from code and wait for it to be closed

I need some help and/or advice please.
I'm opening a file from code in either the default associated windows program or with a selected windows program using either ShellExecute or CreateProcess. I then wait for the process to complete. But this does not really work for me because:
Let's say the default associated program for text files (*.txt) is Notepad ++ (NPP). For the process to complete, NPP must not be open to start with and must be closed to complete the process.
But if NPP is already open, the file will be opened in the already opened NPP. But I do not necessarily want to close NPP to complete the process, I just want to close the opened text file and need to detect that the file has been closed and not NPP.
So I realised that waiting for the process to complete is not going to work. I've tried several things like trying to detect if the if the file is opened in another process but have not had any success.
So my question is, what would be the best method to detect when a file is open or in use and vice versa?
It sounds like you want to know when the file handle is "closed", not necessiarly when the program that operated on that file has exited.
Your question is closely related to this question. You could reference that to periodically poll the process handle to see what files are open. There will be timing issues - it might take a few seconds for the process to open the file in the first place.
There are also tools such as Handle.exe that may be useful.
However - none of these solutions are perfect. Some apps, including Notepad.exe, just open the file, read the contents, and immediately close the handle. When the user clicks "save", the file is re-opened for writing, contents saved back to disk, then the file handle is closed again.
A simpler approach would be to periodically poll the last-modified timestamp on the file via GetFileTime. When it changes, you could assume the file has been "Saved". Or apply this technique with some combination of the above and/or waiting for the application that was launched to exit.

Sublime Text 3: Recover unsaved files lost because of killed application [OSx]

I accidentally force-closed my Sublime Text 3 using Mac's Activity Monitor and when I restarted, Sublime didn't recover all the unsaved files (~50 of them).
I went through several posts in StackOverflow as well Sublime forum, but none of them worked for me. Examples:
StackOverflow Post.
Sublime forum post1: The requester recovered using a file in Project folder. Since I didn't have any Project open, I'm not sure where would I find that kind of a file.
Sublime forum post2: A reply on this post says that I'm pretty much screwed because I was not using Projects.
Anyways, I searched for all the files in my Mac with name "sublime" and found some files like the ones listed below:
/Users/Username/Library/Saved Application State/com.sublimetext.3.savedState/data.data
/Users/Username/Library/Saved Application State/com.sublimetext.3.savedState/window_1.data
/Users/Username/Library/Saved Application State/com.sublimetext.3.savedState/windows.plist
/Users/Username/Library/Application Support/Sublime Text 3/Local/Auto Save Session.sublime_session
/Users/Username/Library/Application Support/Sublime Text 3/Local/Session.sublime_session
/Users/Username/Library/Caches/com.sublimetext.3/Cache.db
/Users/Username/Library/Caches/com.sublimetext.3/Cache.db-shm
/Users/Username/Library/Caches/com.sublimetext.3/Cache.db-wal
/Users/Username/Library/Application Support/CrashReporter/Sublime Text_C6A04335-E900-5C09-B4A3-F203F47923E7.plist
/Users/Username/.Trash/Sublime Text (3114).app/Contents/MacOS/crash_reporter
"file_history" in "Session.sublime_session" does not have names of contents for any of the lost files.
I do have "hot_exit" flag set a false.
I don't know what happened this time for Sublime, otherwise it would always open those (now lost) windows and tabs upon start whenever my Mac has crashed.
I have lost a lot of important details with this(and most likely very costly) mistake. Any help is appreciated.
Thanks
Rajan
The magic is a workable way for me.
Close Sublime Text 3 completely.
Restore this file Auto Save
Session.sublime_session from Time Machine to the "Local"
directory, and choose it by your latest edit and unsaved
timestamp.
/Username/Library/Application Support/Sublime Text 3/Local/Auto Save Session.sublime_session
Reopen Sublime and the unsaved files will show into your eyes.
Surprise! ...and not forget to save them.

Editing Text in Multiple Files with Textwrangler through Automator/Applescript

I currently have an Automator workflow that uses Textwrangler to trim text files down for me.
These files are often full of the same bits of code and spaces, so I made a workflow where I click the Automator action which grabs all the text files in a folder, then uses a Dispense Items Incrementally action to pass them through Automator, where an Applescript runs multiple find/replace queries on each file, before saving and repeating.
All this time, I sit there while the files open, are edited and then closed & saved.
Is there not a way to do this without opening the files themselves? Could I not just tell Textwrangler (using some Applescript command) to grab that folder's text files, mess around with them in the background, and then save them?
The problem with opening them all up on your screen is it increases the chance of some error intefering with the workflow - quite often the workflow encounters some error and so I have to run it again.
(E.g. the way Automator might reduce jpeg picture size in the background is ideal.)
Thanks - happy to take any suggestions!
Tardy

How to close a PDF file using Ruby?

I have been working on Vanilla, a LaTex preprocessor. I and most people open their PDF files to see how their output looks like. But sometimes, we forget to close it down before starting the compiling process again. If the PDF file is open, then the LaTex compiler complains that it cannot write to that file. So I want to add code to the preprocessor which will look if the output PDF file is open and it will close the PDF file if it is open. I have been looking everywhere to see how to go about doing it. I am not an expert in Ruby. I don't want to kill the whole process of Acrobat32.exe or any other PDF viewing program used to view that file because the user might have other PDFs open in the same program. I just need a way to kill the process of that one PDF file. So can anyone suggest me a way to do it?
Can't you just move the old file first, remove it if possible, and then generate a new version of the same PDF with the name you want?

Resources