Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm looking for a script that auto spams pictures of nicholas cage on the desktop
I have this script right now but what I want to do is make it automatically run as soon as the USB is plugged in
import shutil
src = ('Kim.jpg')
dst = ('H:/profile/desktop/Nic')
count = 1
while count < 10:
shutil.copyfile(src, dst + str(count) + ".jpg")
count += 1
Assumption: You are using Windows.
Almost on every new windows platform you need to approve an autorun of any executable so no leads here. But here is an alternative using some social/psychological engineering:
Convert your program to a standalone executable using a tool like py2exe. I assume that after conversion your file is named spammer.exe. Then paste this file in the USB and super-hide it by opening Command Prompt inside your USB and typing:
attrib +h +s +r spammer.exe
Now create a shortcut with and icon of a typical folder of Windows and name it something attractive (if you know what I mean) and point it to spammer.exe. The user (in excitement) clicks at it and Kaboom!
Assuming that you're on a version of windows that isn't too old and you have physical access to the machine in question, you should be able to follow these instructions:
http://windows.microsoft.com/en-us/windows/run-program-automatically-windows-starts#1TC=windows-7
Create a .bat file that executes your script. You could even have the script sleep for a random (or semi-random) period of time before going off.
Related
This question already has answers here:
Python: Get a list of selected files in Explorer (WIndows 7)
(4 answers)
Closed 8 months ago.
My problem is that I am making a program that will get file's data as per the folder that the user has opened as a file explorer... and I have surfed the whole internet to find the answer but it seems that this problem is never faced by anybody before. Many answers are related to the current working directory in which project files are situated.
So, I basically want the path for the folder which is currently being viewed by the user in file explorer...
Best way I can imagine doing that is write your Python software to use context menu in Explorer. With quick googling I found a interesting library for that: https://pypi.org/project/context-menu/
I suppose that there is no sensible way to read data from another process. That would cause security problems.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have written a (python) script which identifies all node on its subnet (NAT subnet) and send an email if the IP address doesn't exist within a record. For this size of project, I don't want to run a database. I think a text file delimited by new lines with an IP address on each would be suitable. What is the appropriate convention for the directory this file would be placed?
There are no real conventions and the answers to this question may be a little opinionated and a lot depends on the script's exact use case.
You have following choices:
datafile in current working directory
datafile in same directory as script
datafile in a folder (that will be created if not existant) relative to the home directory
like three but with an additional profile name
in a system folder like /var/run/toolname
explicit parameter to the script specifies file name
1.) Current working directory
Con:
It forces you to cd into the directory where you have your data, otherwise script won't work or create new data from scratch
Pro:
As the same user on the same machine you could have multiple projects each using its own data.
2.) datafile in same directory as script
Pro:
you don't have to cd anywhere. you know where to find the data.
Con:
you need write permissions to the directory where the script is located (might be a security concern if executed by a web server and if an exploit is found)
only one data file per script
no two users can execute the script with different data
3.) datafile in a folder (that will be created if not existant) relative to the home directory
Pro:
script in one directory but each user has its own data.
if script directory is removed, script is uninstalled and reinstalled the data will persist.
no special write permissions for script dir required.
Con:
you remove the script dir, data persists and might never be deleted.
one user cannot run multiple instances use the script for multiple projects
clean up of data required after uninstall of script
4.( like 3.) but with an additional profile/project name
Pro:
same as for 3.)
one can run multiple projects / profiles in parallel (firefox for example allows to be run with profiles, which are all stored in ~/.mozilla/firefox, but each profile creates its own sub directory ~/.mozilla/firefox/xxxx.profilename
Con:
same as for 3.)
5.) in a system folder like /var/run/toolname
Pro:
could be nice for tools, that run as service / server
Con:
require admin privileges (at least during installation)
6.)
Pro:
you can do whatever you want
Con:
you must specify an additional paramater (except you have the behaviour of the other suggestions as default and the option only if you want to have different behaviour.
All solutions should be fine for you.
For your kind of tool 5.) 3.) 2.) 6.) are probably the better options. I assume your script will be run as a cron job or something alike.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have downloaded some sample tpl files from the internet, i wanted to customise menu on my site thus i was trying to create new base.tpl file. However when I have saved it bottle does not want to read it and and return that:
bottle.TemplateError: Template 'base.tpl' not found.
Strange thing is that one is percived as rtf file and the other one (base.tpl downloaded from the internet) as the exec file. Why is that and how to fix this? Screenshot bellow:
I am referring to them with:
return template('base'). My educated guess is that it is textedit problem (I am using macOS) as it is trying to interpret the file and does not show the real html/tpl content.
Templates are regular bottle tpl files, nothing extraordinary they are saved in my project directory.
As to the directory list
However what I did is downloaded a different text editor then TextEdit and opened it in both in TextEdit you have:
Whereas in Atom text editor it looks like this:
Nevertheless files that were not created in TextEdit work perfectly fine.
Problem was with how the TextEdit perceived .tpl files changing text editor has helped files created via any other editor than TextEdit were interpreted correctly.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have been looking at some python modules and powershell capabilities to try and import some data a database recently kicked out in the form of folders and text files.
File Structure:
Top Level Folder > FOLDER (Device hostname) > Text File (also contains the hostname of device) (with data I need in a single cell in Excel)
The end result I am trying to accomplish is have the first cell be the FOLDER (device name) and the second column contain the text of the text file within that folder.
I found some python modules but they all focus on pulling directly from a text doc...I want to have the script or powershell function iterate through each folder and pull both the folder name and text out.
This is definitely do-able in Powershell. If I understand your question correctly, you're going to want to use Get Child-Itemand Get Content then -recurse if necessary. As far as an export you're going to want to use Out-File which can be a hassle when exporting directly to xlsx. If you had some code to work with I could help better but until then this should get you started in the right direction. I would read up on the Getcommands because Powershell is very simple to write but powerful.
Well, Since you're asking in a general sense -- you can do this project simply in either choice of script languages. If it were me -- and I had to do this job once -- I'd probably just bang out a PoSH script to do it. If this script had to be run repeatedly, and potentially end up with more complex functions I'd probably then switch to Python (but that's just based on my personal preference as PoSH is pretty powerful in a Windows env). Really this seems like a 15 line recursive function in either choice.
You can look up "recursive function in powershell" and the same for python and get plenty of code examples, as File Tree Walks (FTW :) ) are one of the most solved problems on sites like this. You'd just replace whatever the other person is doing in their walk with a read of the file and write. You probably also want to output in CSV format because it's easier and imports into excell just fine.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I wish to know "how", after pasting, the position of the cursor is determent (like with zen coding) programmatically.
With the 'insertion point' I intend to say: that blinking thing where our text shows up when we type.
So, let's say I paste this: '<text>%insertion point</text>'
I want the 'insertion point' to be at a specific location (in this example at %insertion point).
Some details:
I work with/on Linux (Ubuntu/Fluxbox)
Language doesn't really matter (prefer: Python, C, C++ (must be compatible with linux))
With pasting I intend: plain pasting in any text area (not in a terminal)
What I'm 'not' looking for:
a desktop program to do this, unless it's scriptable (such as shell
tools)
a text editor that provide this functionality (such as a vim module)
I'm also curious about tabbing to the next selection so i.e.:
<text>%first</text><detail>%second</detail>
If there is a better place on the internet for asking my question, please let me know about it.
Any information that would point me in the right direction would be highly appreciated.
Thank you for considering my question
EDIT:
I should mention that it doesn't necessary have to be after pasting, the important thing is to manipulate the location of the 'insertion point'.
You could use xvkbd to send the paste key combo CtrlV followed by a series of <- (left arrow) keys to accomplish the template behaviour and then map a Fluxbox keyboard shortcut to executing this command
The command would be something like
xvkbd -text "\Cv\[Left]\[Left]\[Left]\[Left]"
Then assign it to a shortcut in your ~/.fluxbox/keys file (Mod1 is Windows key)
Mod1 P :ExecCommand xvkbd -text "\Cv\[Left]\[Left]\[Left]\[Left]"
However this would need to be customised somehow for each template, and won't work for applications where CtrlV is not "paste" (like xterm). Perhaps for common templates you could just hardcode them to different shortcuts
Mod1 T :ExecCommand xvkbd -text "<text></text>\[Left]\[Left]\[Left]\[Left]\[Left]\[Left]\[Left]"
I suspect you're going to have a better time if you just customise each editor to offer this functionality separately.
EDIT
Here's a Python script that reads from stdin and writes output suitable for xvkbd. It uses the percent sign as the insertion point (eg <text>%</text>), so you need to escape any real percent signs with a backslash.
#!/usr/bin/env python
import sys
import re
clip = sys.stdin.read()
# split on percent sign not prefixed by backslash
parts = re.split(r'(?<!\\)%', clip, 1)
# un-escape percent sign
parts = [p.replace('\\%', '%') for p in parts]
tail_len = len(parts[-1])
print(''.join(parts) + '\[Left]' * tail_len)
You need to pipe the clipboard to it and then pass the result to xvkbd. I'm using xclip here to output the X clipboard to stdout
xclip -out | python pastetemplate.py | xargs -0 -I{} xvkbd -text "{}"
It still has the problem of taking a while to move the cursor, however it does automate the prior process.
I really don't think you're going to have any luck moving the cursor programmatically, as I imagine you'd have to use a different automation library depending on the GUI toolkit of the target app (eg GTK, QT, Flash, etc). However if you target a specific app or toolkit, you might be able to work it out.
Vim stores the position of the previously yanked / pasted / changed text with 2 registers namely '[ for start line and '] for the other end. There are character registers as well to know the exact character virtual column of start & end, read :h '[ for more info.