How to delete a file in imageJ macro - macros

I am trying to write a macro so in imageJ. I want to apply this macro to different image file.
So in the beginning, I save the selected picture with temp.jpg file name
saveAs("Jpeg", "/Users/pathreskoo/Desktop/IHC/temp.jpg");
After I finish the process, I want to delete the file
I try
ok = file.delete("/Users/pathreskoo/Desktop/IHC/temp.jpg");
But the file was not removed. What should I do?

ImageJ macro is case sensitive. Try using File.delete, not file.delete.
https://imagej.nih.gov/ij/developer/macro/functions.html#File.delete

Related

Rename file with the information available in it

Issue - I have this large batch of pdf, word & notepad files which are required to be renamed according to the text available in each file.
For eg: I have to open file A, search the entire document for the string which will be used as its name, copy, close the file and rename the file.
After searching for some while I found that autohotkey can help me with this though I'm open to every solution. What I want to do is open the file, search for the name, select the text and use the keystroke to close and rename the file.
Could anyone help me with this?
I'm not going to give you a script but what you want can be done.
You need to collect various pieces of information when you rename a file. One of them being the current file name which you can often grab from the window title. You can use https://autohotkey.com/docs/commands/WinGetTitle.htm
If a filename is wrapped in [ ] you can remove those using https://autohotkey.com/docs/commands/StringReplace.htm
If you know the file path (folder where the file resides in) you can now use https://autohotkey.com/docs/commands/FileMove.htm to rename a file and use https://autohotkey.com/docs/misc/Clipboard.htm as a variable.
You would probably like to retain the extension (.doc, .txt, .pdf) so you can use https://autohotkey.com/docs/commands/SplitPath.htm to grab it and append that to the clipboard when you rename it.
Closing a file depends on your program, sometimes you can send ctrl+w or ctrl+w or you need to use the WinClose command so you need to add in that step before you use FileMove.

How to change Excel 2013 Template Miniature

Is there a simple way to change / replace the automatically generated Template Miniature with a different image.
I have checked this out for Excel 2016 but the process is similar.
First, the thumbnail is generated and part of the file. There is no official process. A description for brave Office pros is shown below.
You can do this:
First, close Excel!
Get to the location of your template
Make a copy
Rename the file extension to .zip
Unzip the file into a new folder using the Windows Zip utility
Search the tree of files for a file called thumbnail.wmf
Open PowerPoint and create an empty presentation
Use the function "Insert an Image" and add the thumbnail.wmf to the slide
Remove everything else from the slide
Try to ungroup - it fails with a message asking to convert to a drawing object
From here you have two options. Either convert, ungroup, change and proceed or throw away and create a new image from scratch.
Work on image and group your image (the old or a new one), then
Right click on the grouped image and click "Save as picture"
Choose the filetype "wmf" and name it the same as before and overwrite the existing thumbnail.wmf
Go INTO the folder using Windows Explorer of unpacked files, hit Ctrl-A (Select All)
Right click and say "Send to" --> "Compressed (zipped) folder". Give it a new name.
Hit F2 to rename the file
Remove the file extension .zip
Now, open Excel!
Hit "New", "Personal" and you see your template with your custom image in full width and height. Repeat steps 10 to 16 until you're satisfied.
Drawbacks: Once you edit your file in excel and save as template with thumbnails option (advanced properties) switched on, Excel will overwrite your custom wmf-file. You have to repeat the steps "Unpack -> Replace File -> Pack" every time.
I'll post an update once I found a better solution.
Here is an automation of the process that might help with understanding the process described in the answer.
Python 3 code snippet
import zipfile
import shutil
exfilename = 'MYTEMPLATE.xltm'
a_path='C:\\TEMP'
th_path='mythumbnail.wmf'
with zipfile.ZipFile (exfilename, 'r') as zf:
#Extract to temporary folder
zf.extractall(a_path)
#replace the thumbnail
shutil.copyfile(th_path,a_path+'\\docProps\\thumbnail.wmf')
#remake the zip as a new file
shutil.make_archive('TEMP_ARCHIVE','zip',a_path)
#rename back to original, replacing original
shutil.move('TEMP_ARCHIVE.zip',exfilename)
#clean-up temporary files
shutil.rmtree(a_path)

rename GUI file and callbacks

I've renamed My ".m" and ".fig" on the same name, in my "*.m" i've replaced occurrence of previous name with the new one.
Is any efficient way to rename a simple GUI file without renaming all the callbacks (in the property panel) on the "*.fig" file ?
Have so many callbacks and button that it's really fastidious to make it manually.
Thanks !
I usually open the .fig file in GUIDE, save it with an other name, and with default options a new .m file should be created with the new name.
Callbacks should also be renamed automatically if you didn't change their '%auto' option in GUIDE.
Hope that helps !

I Want Users Browse The File, But It Affects to My Script

I'm doing with MATLAB.
I have a file named 'cobat'. Cobat is a *txt file, tab delimited, consisted of 3 coloumns, so it's a table. I load it manually into this script:
I want users browse their own file. How can I do it? Is this code correct:
[filename pathname] = uigetfile(('.txt'), 'Browse Your File')
Here are my problems:
I think it is only for text file, not tab delimited (table). I think I have to use uitable, but I don't understand how to implement it, because the file (cobat) should be loaded.
And, if it has been implemented, I can't write 'cobat' in my script, like this:
[g c] = kmeans(cobat,k,'dist','SqEuclidean'); y = [cobat g]
Then I have to change 'cobat' to what name?
Thank you.
You are on the right track. After locating the file you need to load it:
load([pathname filesep filename])
If file name is cobat (or cobat.txt), it will create a matrix called cobat in the workspace with the content of the file.

How to conver this text file to proper cell array - Matlab

Alright this is the text file
{'samsung','n150','jp0xtr','n570','2gb','320gb','10','w7str'};
{'samsung','n150','jp0xtr','beyaz','intel','atom','n570','66','ghz','2048mb','ddr3','320gb','10','cam','bt','w7str'};
{'samsung','n150','jp0xtr','atom','n570','66ghz','2gb','320gb','10','netbook','w7s','beyaz'};
{'samsung','n150','jp0xtr','atom','n570','66ghz','2gb','320gb','10','netbook','w7s','beyaz'};
{'samsung','n150','jp0xtr','intel','atom','n570','66ghz','2gb','320gb','10','win7starter'};
{'samsung','n150jp0xtr','n570','2g','320gb','10','w7s','beyaz'};
{'samsung','n150','jp0xtr'};
{'samsung','n150','jp0xtr'};
Now i want to load it as the below cell array
I used copy paste here but i want to do that via file reading (text file). How can i do that ? Thank you.
Just edit the text file to that it starts with C = { and also ends in } and change the extension to .m. Then run it as if it was a script from matlab command-line.
Next time do not copy and paste, use the save command as in save ('monitor-list.txt', 'C', '-ASCII'). You can then load it easily with load path-to-file.