Powershell - get status of Win 7 slideshow - powershell

Quick summary of question: In Windows 7, using Powershell or a little C#, how can we tell if a custom theme is going to leave a single image or do a slideshow in the background?
(Related questions but not quite the same and not answered:
How to resume Windows 7 slideshow after restoring default wallpaper (not answered / separate issue)
https://stackoverflow.com/questions/10556820/programatically-enable-windows-7-desktop-slideshow (not answered / separate issue)
How can I detect wallpaper changing as a result of the Windows 7 slideshow? (answers don't work for win 7 / separate issue)
Related resource, but didn't help:
http://www.heckler.com.br/blog/2011/03/29/desktop-background-slideshow-in-windows-home-basic-with-powershell/
)
The question is pretty much what it sounds like, and I am not sure why it is having so much trouble.
In Win8 I can use technique's based on Andy's post ( Powershell script from shortcut to change desktop ) to get the source image. From there and from what I can tell, slideshow always ends up in TranscodedWallpaper.jpg, and as soon as you drop to a single image it switches to the name of the image. So a bit round-about, but I can tell if slideshow is on
In Win7 I can check WallpaperSource
Get-ItemProperty 'HKCU:\Software\Microsoft\Internet Explorer\Desktop\General' WallpaperSource
but it only gives me the current image if there is a slideshow, and if we are using a 'Custom.theme' then
Get-ItemProperty -path 'HKCU:Control Panel\Desktop' -name 'Wallpaper'
returns TranscodedWallpaper.jpg each time, even if there is only one image left in there and no time interval. (Regardless if I use the above command or Andy's script)
I've tried running Process Monitor to figure out what windows does, and it plays a little in 'C:\Windows\Globalization\MCT\MCT-US\Wallpaper\desktop.ini' but it doesn't seem to leave any marks I can use. It helped me find
Get-ItemProperty -path 'HKCU:Control Panel\Personalization\Desktop Slideshow'
which has a Shuffle and Interval field, but neither changes when we are in a Custom theme - single image vs a Custom theme - slideshow.
I am sure I am missing very obvious (being new to playing on this end of Windows and Powershell).. any thoughts?

Took a while but I figured it out (or figured out a solution). If anyone else runs across this, Win 7 has an ini file:
C:\Users\[...]\AppData\Roaming\Microsoft\Windows\Themes\slideshow.ini
When there is only one picture in the 'slideshow' this file becomes empty, so using .WallpaperSource is the correct background image. When there are multiple images in a slideshow then this file has content (the information on transitioning the background) so even if .WallpaperSource seems like the right image, it will likely change over time based on the interval.
In short, from what I can see (and until I run across the situation that breaks this rule and I go back to the drawing board), to see if you have a slideshow you:
$doesFileExist = Test-Path $PATH_TO_THE_INI_FILE
if ($doesFileExist){
$iniContent = Get_Content $PATH_TO_THE_INI_FILE
if ($iniContent){
# This was a slideshow
}
else {
# This does not seem to be a slideshow
}
}
(This is of course only for the build in Windows 7 functionality, no idea how it would react to all the custom code and apps out there). And the Win 8 solution is up in the initial question

Related

Moving files to different location based on color tag using AppleScript

I'm a bit new to AppleScript. I would like to start moving files that are tagged "green" in finder to a different location. This would be to start with.
Ideally, I'm using the program "Capture One" and within that program you can tag images green which is stored as metadata. I would like to write an AppleScript to scan the image folder for any images with the metadata tag "green" and move those images to another location on a server. I would like to have the script scan the folder every hour.
I have searched around quite a bit and have found difficulty in getting a clear idea on how to approach this process.
Thank you kindly for your time and help!
Disclaimer: this is the "no-applescript" answer. I asked in comments
if applescript was a requirement, answer was no, so I explored
non-applescript solutions. I imagine a proper applescript-based
solution is still welcome.
You can create a shell script to do that:
#!/bin/sh
SOURCE_FOLDER="/path/to/source/folder"
TARGET_FOLDER="/path/to/target/folder"
find "$SOURCE_FOLDER" -type f | while read file
do
mdls -name kMDItemUserTags "$file" | grep Green && mv "$file" "$TARGET_FOLDER"
done
See How do I set a task to run every so often? to schedule this every hour.
Edit: I have long forgotten how to write Applescript, but for a double-clickable application with no code, you can try with "Automator":
New -> Application
from Library, select "Files & Folders"
pick "Find Finder Items" and drag it to your workflow
pick "Move Finder Items" and drag it to your workflow
(although this will work for files that have the Green tag and no other tag, but you can specify more complex rules)

Matlab control+enter key on figure

I want to capture when the user holds down the control key and presses the enter key on a figure window. Note: This is the default keys for "Evaluate Current Section" in the editor.
See example code below:
function test
f = figure;
f.KeyPressFcn = #myKeyPressFcn;
end
function myKeyPressFcn ( hFig, event )
cm = hFig.CurrentModifier();
if ~isempty ( cm )
fprintf ( 'CurrentKey: %s:%s\n', cm{1}, hFig.CurrentKey );
else
fprintf ( 'CurrentKey: %s\n', hFig.CurrentKey );
end
end
To reproduce save the above in an active file in the editor and run the function - the editor needs to be open (this is important!!).
With the figure active press any key -> the selected key is written to the terminal window. However if you hold down Control and press the enter (return) key then this is not captured but instead Matlab attempts to "Evaluate Current Section" (or cell as it used to be called) in the editor (no matter that the figure has the focus). This of course throws as error...
I have contacted Matlab support and this is "expected behaviour!". I can (just about) see why it might be a good idea for demos - but for professional applications that run in Matlab I personally think this "feature" is a bug!!
Notes
When the editor is closed the control+enter is captured in the figure
In deployed applications the control+enter is captured.
If I manually change the Evaluate Current Section shortcut then control+enter is captured.
I have tried a number of things to resolve this but none have worked, for example hiding the editor or setting editor enable state to false (neither of these are acceptable solutions - I was trying to see what I could get to work on a small test case...):
function test
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
jEditor.setVisible(false);
jEditor.setEnable(false);
f = figure
f.KeyPressFcn = #myKeyPressFcn;
uiwait(f);
jEditor.setVisible(true);
jEditor.setEnable(true);
end
The only way I can get it to work is to close all of the editor files on launching the GUI and then opening them again when the GUI closes (this is not an acceptable solution... - for fairly obvious reasons!!)
I did think about trying to temporarily modify the shortcut key (Preferences-Keyboard-Shortcuts) of the "Evaluate Current Section" -> but haven't worked out a way to do it from the commandline, and then set it back again when finished. If this is fast you could do it when the user presses and releases the control key.
So what am I asking:
If possible I need a solution that will work for anyone anywhere - as if I can get this to work it will be included in a new add-on feature in my Matlab GUI Toolbox. - which is used by people all over the world.
Do you know how to modify the keyboard shortcuts from the commandline - if so how!
Any other suggestions?
My other idea is to change my shortcut to a different key combination - but wheres the fun in that! :) (I will still have the issue if some user somewhere has altered the execute the current cell to my new combination...)
P.S. Thanks for reading this far down!! :)
Why don't you go to the home> Preferences > keyboard > Shortcutand change it there?
you only need to hit Ctrl + Enter in the black box at top of the page for searching the related command, which is here Evaluate Current Section and change it whatever you like.
Please bear in mind you will only need to split out your windows (Undock them). Then, when you click on Ctrl + Enter, it will do whatever you would like.
I hope you find this answer helpful.
You can try the solution from my FEX submission. The KbTimer is motivated by the need to capture keyboard stroke without the need of GUI that designed either by GUIDE or APP DESIGNER. Note that the implementation of function was inspired from the PsychToolbox which is MEX based.

Creating, recreating many Emacs-windows

From time to time I would like to create a bunch of say 8 windows with some fixed names, with some shells, all split vertically. So I do a lot of C-x 2 and rearrange the window size. Isn't there a better way to do this?
So the desktop saver is no help to me, unless I missed something.
(By windows, I mean emacs-windows, not the windows "window-managers" are built-for which you can Alt-Tab to)
You can store your current window layout to the Configurations register
However, to make it persistent across sessions, you might need a tool like Policy Switch.
Emacs Screen also looks very promising for what you want.
This is something that I have been meaning to do for myself for a long time; appreciate the nudge ;)
While there are various prepackaged solutions for recording and saving windows and frame congurations as alluded to in the other answer, it is quite easy to do this directly.
You can call 'make-frame' directly with the frame parameters you want. An example may look like this:
(make-frame '((name . "(SHELL)")
(icon-name . "(SHELL)")
(icon-type)
(top . 720)
(left . 1300)
(height . 30)
(width . 81)))
This call will not only create the frame (in case you are running under a windowing system) but also return the newly created frame.
If you want a quick peek at what parameters are available, you can make a call like this:
(frame-parameters)
which will return the parameters of the currently selected frame.
You can change one or more parameters of a frame with 'modify-frame-parameters' and get a list of all frames with 'frames-on-display-list'.
There are many more nifty functions that allows you to deal with frames. Check the documentation for more info.

How to stop a Matlab script but don’t kill the process? [duplicate]

This question already has answers here:
Stop and continue execution from debugger possible?
(6 answers)
Closed 8 years ago.
Strg+C stops and kills a Matlab script (at least sometimes). But is there a way to stop a Matlab, take a look at some variables and continue the calculation?
I am not talking about just setting a breakpoint. I want my script, let’s say run for couple hours come back to it hit some buttons that stops the calculations take a look at some variable and then continue the calculation.
I tried to find out if there is some shortcut key for this – I am quite sure there isn’t.
Now I was thinking about including an if-case that looks if a certain button was pressed by the user. If so there would be a useless k=0 line and a breakpoint on it. And if no one is pressing this button the loop would continue. But this is where my limited Matlab knowledge leaves me. I don’t know if there is a way to ask for a user-button press but don’t wait for a button press like in the function input. Also I just have a running script, I don’t have any GUI.
To drop to the command prompt you need the command keyboard and then type return when you have finished (you don't need a breakpoint). The tricky bit is how to trigger it. There a few options. The easiest is to open a figure window. The following code halts the process when any key is pressed.
keyDownListener=#(src,event) keyboard;
fig = figure;
drawnow
set(fig,'KeyPressFcn',keyDownListener)
for p=1:10000
%do some thing
end
You can modify this to test for a specific key since the keypress is contained within the event struct.
To use no figure gui at all its more of a problem. I'm not aware of a non blocking keyboard input method. A mex file the runs kbhit() in C might do it, but kbhit() is not standard C so it would only work on Windows. An easier option maybe to test for the presence of a file.
for p=1:100000
if exist(fullfile(pwd,'halt.tmp'),'file')
keyboard
end
%do something here
end
This drops to the debug console when halt.tmp is created in the current directory.
Other potential methods could involve using multiple threads to read 'input' (either the Parallel computer toolbox or undocumented Java code), or using http://psychtoolbox.org/ as mentioned by #bdecaf

Disable auto-scrolling in command window

A lot of the code that I write in Matlab has a very verbose output. As the program runs, information is printed to the command window, and with each new line, the window automatically scrolls to the bottom. This becomes a problem when I want to read some of the output more closely or scroll up to look at older output. I can scroll up, but only until a new line is printed, which is often less than a second.
Does anyone know if it is possible to turn off this automatic scrolling in the Matlab window? I work in a number of different Matlab versions, depending on the machine, and this happens with all of them. The answer to this might be "No", but I swear I remember having this functionality at one point.
Use the more function: http://www.mathworks.com/help/matlab/ref/more.html
more on
Then run your program. Press spacebar when you wish to see more of the output.
more off will turn it off.
You may find this workaround useful.
First launch matlab using the command line matlab -logfile 'myLog.txt' (the doc says it "starts MATLAB and makes a copy of any output to the Command Window in filename. This includes all crash reports.")
Then open your .txt file using a text editor supporting automatic refresh of content (see picture). On OSX I use TextWrangler (freely available at www) but others have been reported to have this feature (see here or here).
Results: output displays (fprintf, disp, but not the commands per se) are printed both on the Matlab console and the text editor (file is refreshed with a little lag time, below half a second I would say with my configuration). And there is no automatic scrolling. Such procedure does not seem to impact the overall performance of the script (although it may deserve some testing).