r/dailyscripts • • Sep 15 '15

[Batch][Windows] Wrote a script to remotely rename network computers from a server

16 Upvotes

A client asked us to rename every workstation in the environment. I made it a little easier.

@ECHO OFF
set /p oname="Enter original name: " 
set /p nname="Enter new name: " 
set /P c=Are you sure you want to continue[Y/N]?
if /I "%c%" EQU "Y" goto :rename
if /I "%c%" EQU "N" goto :end
:rename
echo You chose to name %oname% as %nname%
set /p user="Enter domain\user: " 
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
    [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set pass=%%p
netdom renamecomputer %oname% /newname:%nname% /userD:%user% /passwordd:%pass%
pause
exit
:end
echo You chose not to do anything
pause
exit

r/dailyscripts • • Mar 10 '14

Markdown for LibreOffice (Openoffice)

11 Upvotes

I hate jump from keyboard to mouse and back and I hate learning dozens of hotkeys so I studiously avoid using office packets. I prefer to use markdown

But I have to write lots of document in odt format (odt is corporate standard) with pictures, complex tables and formulas and so on. I tried to write markdown and convert to odt with pandoc, but I reveal that working with tables and pictures is much simple through GUI. Converting is not ideal as well, for example when I want automatic TOC and illustration list.

So I decided to make Libreoffice extension to support markdown. It turned out that writing extension is not a piece of cake and openoffice api is complicated as the f.ck. Suddenly it is so "dynamic" that it's easier to write in basic then in java. Beside that, even simple tasks require hours of digging the net.

So I ended up with My markdown Macro that do three tasks:

*format headers *format code *format formulas

It took two weekends to write, and now I feel tired bored and annoyed. It so uncool to work with OOBAsic and OOApi. So dear Reddits I ask you, Is it worth it to continue development? Is such functionality demanded by somebody besides me?


r/dailyscripts • • Jan 23 '14

[Batch] Turn your desktop into your SkyDrive or Dropbox cloud folder - One-liner

11 Upvotes

Submitted this to /r/lifehacks, and subsequently got downvoted...probably a bit too complex to be a lifehack.

Anyway:

Create a symbolic link (google if you don't know) from your SkyDrive to your Desktop folder using this line of code:

mklink /D /J %USERPROFILE%\Desktop FullPathToCloudStorageFolder

To use:

  1. Replace "FullPathToCloudStorageFolder" with the location of your cloud storage folder (e.g. C:\Users\HeckDeck\Skydrive). If there is a space in the path surround it with quotes (e.g. "C:\Users\New Folder\SkyDrive")

  2. Back up your entire "Desktop" folder somewhere

  3. Delete your "Desktop" folder (C:\Users\USERNAME\Desktop), your system may complain about a missing folder, ignore this

  4. Open command prompt and run the command, this will create the "Desktop" folder and link it to the folder you specified.

  5. The folders and files from the folder should appear on your desktop, if you don't see them click on your desktop and press F5

This means that all files on your desktop are the files in your SkyDrive, so treat them as such.

I use this to link my SkyDrive folder, which is a real time saver when editing scripts and photos. I've tested this with both SkyDrive and Dropbox.

To remove the link simply delete the "Desktop" folder, this will not affect your files. The "Desktop" folder you created is simply a link telling the operating system to treat the folder like a shortcut to the folder you specified.

Edit: Misplaced a line of text on step 2. Relocated to the correct place. - 23.1.2014


r/dailyscripts • • Jan 10 '14

[BASH] batch convert word documents to PDF

10 Upvotes

pastebin link: http://pastebin.com/WnM4yhJc

How to use it: save it, make it executable, call it like this: ./convert-to-pdf.sh [directory] [delete after conversion(y/n)] [run recursivly (y/n)]

Directory is the directory you want it to run in, delete after conversion will delete all of the word documents it processes after it converts them to PDF. The last option is self explanatory.

The story: I had a bunch of screenshots of online order recipts I saved as word documents (before I knew better), and I wanted to convert them to PDFs.

Edit: I just notice that it calls itself recursively from its absolute path in my user folder, you will need to change the line "find $1 -type d -exec bash -c "cd '{}' && /home/main/Scripts/convert_to_pdf.sh '{}' $2 n" ;" to your install directory for this script.


r/dailyscripts • • Aug 03 '13

[Autohotkey] - ac'tivAid - collection of useful AHK-scripts

10 Upvotes

One of the first things I install on a new Windows PC is ac'tivAid, a collection of about 60 AHK-scripts by renowned german IT magazine c't. I've only installed a few of them, but I use these all the time and couldn't live without anymore. You run the .exe and can then choose which scripts to install from a list (like installing an addon in a browser).

Some of the handy highlights:

  • AppLauncher - self-explaining

  • MusicPlayerControl - control Foobar et al. via Hotkeys

  • MinimizeToTray - self-explaining

  • PastePlain - remove metadata when pasting from the clipboard

  • RemoveDriveHotkey - eject USB-devices via hotkey

  • VolumeControl - control master volume via hotkey

I run the german version, but apparently you can choose the english version when installing it.

Edit: Formatting


r/dailyscripts • • Jul 26 '13

[BATCH] These are the sad lengths I'll go to for a little convenience in the face of adversity.

10 Upvotes

I'm a big fan of PuTTY for several reasons, but two big ones are the ability to store commonly used addresses and the automatic logging. I've got a copy on every system I use at work except one where the standing rule is no additional software is allowed. There is an often exploited loophole however that batch files and perl scripts are just fine (go figure). Not willing to give up my two favorite features of putty I put this together. It's a bit ugly, but it does the job so I figured I'd share.

@echo off
REM ====================================================================================================
REM  telnet.bat 
REM ====================================================================================================

REM TEST FOR TELNET DIR AND CREATE IF NEEDED
if not exist c:\telnet\con md c:\telnet\

REM GET TIME AND BUILD FILENAME
REM for %%x in (%time%) do set now=%%x
for /F "tokens=1-4 delims=:., " %%a in ("%TIME%") do set TT1=%%a
for /F "tokens=1-4 delims=:., " %%a in ("%TIME%") do set TT2=%%b
for /F "tokens=1-4 delims=:., " %%a in ("%TIME%") do set TT3=%%c
set logg=%TT1%.%TT2%.%TT3%.txt
set tempfile=%TT1%.%TT2%.%TT3%.tmp
set ltime = %time%

REM GET DATE AND CREATE A FOLDER IF IT'S NOT ALREADY THERE
for /F "tokens=1-4 delims=/. " %%A in ('date/T') do set TD1=%%B
for /F "tokens=1-4 delims=/. " %%A in ('date/T') do set TD2=%%C
for /F "tokens=1-4 delims=/. " %%A in ('date/T') do set TD3=%%D
set today=%TD1%.%TD2%.%TD3%
set year=%TD3%
IF %td1% == 01 set month=JAN
IF %td1% == 02 set month=FEB
IF %td1% == 03 set month=MAR
IF %td1% == 04 set month=APR
IF %td1% == 05 set month=MAY
IF %td1% == 06 set month=JUN
IF %td1% == 07 set month=JUL
IF %td1% == 08 set month=AUG
IF %td1% == 09 set month=SEP
IF %td1% == 10 set month=OCT
IF %td1% == 11 set month=NOV
IF %td1% == 12 set month=DEC
If not exist c:\telnet\%year% md c:\telnet\%year%
if not exist c:\telnet\%year%\%month% md c:\telnet\%year%\%month%
if not exist c:\telnet\%year%\%month%\%today% md c:\telnet\%year%\%month%\%today%

REM  ADD HEADER TO LOG FILE
echo. >>c:\telnet\%year%\%month%\%today%\%logg%
echo =============================================================== >> c:\telnet\%year%\%month%\%today%\%logg%
echo TELNET LOG >> c:\telnet\%year%\%month%\%today%\%logg%
echo Command: %0 %1 >> c:\telnet\%year%\%month%\%today%\%logg%
echo Date: %date% >> c:\telnet\%year%\%month%\%today%\%logg%
echo Start Time: %time% >> c:\telnet\%year%\%month%\%today%\%logg%
echo =============================================================== >> c:\telnet\%year%\%month%\%today%\%logg%
echo. >>c:\telnet\%year%\%month%\%today%\%logg%
echo. >>c:\telnet\%year%\%month%\%today%\%logg%
 
REM CHECK FOR COMMAND LINE ARGUMENTS (I incuded NY and atlanta as examples, I've normally got about 30 of these)
IF "%1" == "" goto blank
IF "%1" == "ny" goto NY
IF "%1" == "atlanta" goto atlanta01
goto other

REM  START TELNET  
:blank
c:\windows\system32\telnet.exe -f c:\telnet\%year%\%month%\%today%\%tempfile%
goto done
     
:NY
c:\windows\system32\telnet.exe -f c:\telnet\%year%\%month%\%today%\%tempfile% 127.0.0.1
goto done

:atlanta01
c:\windows\system32\telnet.exe -f c:\telnet\%year%\%month%\%today%\%tempfile% atlanta01.network4.whatever.net
goto done

:other
c:\windows\system32\telnet.exe -f c:\telnet\%year%\%month%\%today%\%tempfile% %1
goto done

:done
REM  COMBINE TELNET OUTPUT WITH LOG FILE
copy c:\telnet\%year%\%month%\%today%\%logg% + c:\telnet\%year%\%month%\%today%\%tempfile% c:\telnet\%year%\%month%\%today%\%logg% /y > nul 2>&1

REM  ADD FOOTER TO LOG FILE
echo. >>c:\telnet\%year%\%month%\%today%\%logg%
echo. >>c:\telnet\%year%\%month%\%today%\%logg%
echo. >>c:\telnet\%year%\%month%\%today%\%logg%
echo =============================================================== >> c:\telnet\%year%\%month%\%today%\%logg%
echo END OF TELNET LOG >> c:\telnet\%year%\%month%\%today%\%logg%
echo Date: %date% >> c:\telnet\%year%\%month%\%today%\%logg%
echo End Time: %time% >> c:\telnet\%year%\%month%\%today%\%logg%
echo =============================================================== >> c:\telnet\%year%\%month%\%today%\%logg%

REM DELETE TEMP FILE CREATED TO HOLD TELNET OUTPUT
DEL c:\telnet\%year%\%month%\%today%\%tempfile% /Q

r/dailyscripts • • Sep 20 '18

Script to periodically archive files.

9 Upvotes

I created this script because I have an application that runs on a dataset containing 60000 lines every night. The log files for these actions can get quite large and the larger the files are, the worse the application performs (taking up to 48 hours to run when the logs need to be cleared.) If they are freshly cleared, the application will only take 1 hour to run.

This script runs once a night. It creates a zip file from the logs directory and stores them in the logsbackup directory. It will hold on to the archives for two weeks before deleting them. It uses pattern matching on the filename to determine which ones should be kept and which deleted. It is probably a bit overkill, but I'm tired of clearing logs by hand.

#Configuration Items
$source = "C:\Path\to\logs"
$destination = "C:\Path\to\logsbackup"

#File naming convention is formatted as 4 digit year 2 digit month and 2 digit day.
$filename = "$((Get-Date -format "yyyyMMdd").ToString()).zip"
#Uncomment below for debugging
#Write-Host "$destination\$filename"

#Create zipfile from folder
Add-Type -assembly "System.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($source, "$destination\$filename")

#Delete log directory
Remove-Item $source -Recurse -Force

#Iterate through old logs and delete ones that are no longer needed.
#Uses pattern matching based on the file naming convention"
$regex = "(?<zipdate>\d\d\d\d\d\d\d\d)\.zip"

$files = Get-ChildItem $destination -File
Foreach($file in $files)
{
    #if it matches the pattern, calculate the date, then delete files older than two weeks
    if ($file.Name -match $regex)
    {
        $zipdate = [DateTime]::ParseExact($Matches.zipdate,"yyyyMMdd",$null)
        Write-Host $zipdate
        if($zipdate -lt ((Get-Date).AddDays(-14)))
        {
             Remove-Item $file.FullName
        }
    }
}

r/dailyscripts • • Apr 27 '15

Good place to learn scripting?

9 Upvotes

Hello! User of Greasemonkey here! Was wondering if anyone knew a good place to learn scripting. Somewhat of a newb


r/dailyscripts • • Oct 14 '14

[Python] Download last 1000 comments from a user account, result is neatly formatted HTML file

9 Upvotes

r/dailyscripts • • Apr 02 '14

[Python 2.7] Categorize Torrent/Usenet dump folder into proper folder tree.

9 Upvotes

Just a little script I wrote to categorize movies and tv shows from torrents into a nice looking folders.

http://pastebin.com/raw.php?i=XfREqXXf

without comments: http://pastebin.com/raw.php?i=Nm2vZnYd (because I started and didn't finish because a coworker didn't really care :))

From -> To screenshot: http://i.imgur.com/0WEyVLS.png

Let me know what you think... command flags are at the bottom:

C:\Users\blake\Desktop>spyrit -h
usage: spyrit.py [-h] [-s FOLDER_SOURCE] [-d FOLDER_DESTINATION] [-v] [-f]
                 [-abc ABC]

Sort a hodge-podge of downloads based on keywords

optional arguments:
  -h, --help            show this help message and exit

  -s FOLDER_SOURCE, --source FOLDER_SOURCE
                        The root folder containing items to be sorted.
  
  -d FOLDER_DESTINATION, --destination FOLDER_DESTINATION
                        The root destination folder where items and new
                        folders will be placed.

  -v, --verbose         Display processing messages.
  
  -f, --force           Allow spyrit to create new folders if they don't exist
  
  -abc ABC, --alphabetize ABC
                        Sub-organize under keywords by alphabet, ex:
                        Media/TV/_A_/Archer .. activated with -abc TV

r/dailyscripts • • Feb 12 '14

[BATCH] Remove Windows Features - (Windows Vista, 7, & 8)

9 Upvotes

Here's a quick way to remove Windows features. Alternatively, go to "Programs and Features" in control panel to manually uninstall via the "Turn Windows Features on or off" link.

The following example uninstalls the Windows Fax and Scan feature:

start /wait pkgmgr /uu:FaxServicesClientPackage /norestart /quiet

There are other features you have the option of removing such as Windows Gadgets:

start /wait pkgmgr /uu:WindowsGadgetPlatform /norestart /quiet

These are other features I remove on clean installations of Windows 7 in non-server environments:

start /wait pkgmgr /uu:MediaPlayback /norestart /quiet
start /wait pkgmgr /uu:Xps-Foundation-Xps-Viewer /norestart /quiet
start /wait pkgmgr /uu:Printing-XPSServices-Features /norestart /quiet
start /wait pkgmgr /uu:Printing-Foundation-Features /norestart /quiet

If an SSD is installed I also run this to remove the indexing service start /w pkgmgr /uu:Indexing-Service-Package /norestart /quiet

Full list of features (also called packages): Vista, Windows 7, Windows 8. Check out the other pkgmgr.exe command-line options.

Be sure to document the features you remove in case you need them in the future.

Happy scripting!


P.S. An alternative would be to disable the services associated with these packages and disable or uninstall the drivers they use. However, this is a more efficient and Microsoft approved method.


r/dailyscripts • • Aug 12 '13

[Python] Convert all the markdown files in a folder to pdf using Pandoc

9 Upvotes

I've done a few online courses through Coursera and Udacity, and I've found the best way to get the information to stick is to have a text editor open next to the lecture videos and take notes in Markdown.

Once I've written the notes, I run them through pandoc to get prettified pdfs that I can refer to later. This script basically just calls pandoc on each markdown file in the folder it's dropped into, with some basic caching where it only updates pdf's for files modified since the last time the script was run.

The script is up on Github here, let me know what you think.


r/dailyscripts • • Dec 25 '17

A script that adds metadata to your music files

8 Upvotes

So I wrote this small script that adds album art, artist name, album name, etc etc and all those goodies to your music files.


r/dailyscripts • • Dec 14 '17

Job searching is a bitch

8 Upvotes

I am fucking annoyed with tech recruiters, just seems like you just cannot satisfy them. This rampage is existing because these recruiters are just wasting our time with each other.

I have been a contractor for front end web development for a couple of years now so I can gain experience and find companies I will enjoy being with.

A recruiter reached out to me and thought I was a good candidate, note he contacted me on LinkedIn so he saw my recent experiences that I publish on the site. Later on, during the week he contracted me back and told me that my resume looks jumpy and I need to ‘commit’ to a company for 3+ years. I explained it to him that in order for recruiters to even look at my resume and codes I needed to gain experience; the best way doing contracted roles. It helped me pay my bills and I do not have significant gaps of employment. He continues saying that my resume does not define that there were short term. I explained to him originally it did but other recruiters told me to take it out so I can explain it to them why was my time so short and why did I choose to do contract roles for the past two years. He continues by stating I look more like a UI/UX designer, a lot of companies want that for their front-end developers.   I told him I have been looking for a full time long term role for about a year and a half. He then said ‘well you need to get out of contracts because that is what recruiters will see you’. THAT IS WHAT I AM TRYING TO DO. I am not trying to make a fucking loop and it seems constricting as fuck. Instead of working at a company that did not do what I was interested or sitting around and polishing my portfolio or building a app, I worked in different companies and learned as much as I can and it is still not enough. I just want recruiters to do the following better: 1In detail, tell what level experience you want for the role. It will make me not attempt to send an email to you unless I really like the company. 2FUCKING READ! Recruiters takes 30 seconds to a minute to judge, use it wisely. If you too tired to read, take a break work on something else. 3Make notes 4Figure out how to pronounce someone name correctly, if you do not know how, ask. Really not that difficult. 5Stick to what you want people to note. I have 4 different kind of resumes for my field of interest. I understand my cover letter needs to be adjust often, but FOUR resumes for the same thing is stupid.

I get it that your job is stressful… but you are not the only one also you make it frustrate the hell out the other people out there looking for work.


r/dailyscripts • • Feb 17 '16

Quick Question about this subreddit

8 Upvotes

Why is the page title "niggard"?
nig·gard
ˈniɡərd/
noun

  1. a stingy or ungenerous person.


r/dailyscripts • • Feb 02 '16

I need a FFMPEG script to convert all Webm files in a folder to Gif, and then delete those Webm files

8 Upvotes

I'm using FFmpeg with DirectoryMonitor, a folder watching program. When a webm is added to the folder i want to execute a script to convert all webm files in that folder to gif, and then delete those webm files. Thanks for reading, answering and breathing precious fumes.


r/dailyscripts • • Feb 11 '14

[HOWTO] Pin Script Files to the Taskbar or Start Menu - (Windows 7)

8 Upvotes

This is not a script, but a technique to improve script management. Ever wondered how to pin scripts to your taskbar?

For this example I'll be using a batch script:

  1. Create a batch script to pin to your Taskbar or Start Menu. I used this one.

  2. Create a new shortcut to your batch script on your local drive

  3. Open the properties of the shortcut and select the "Shortcut" tab

  4. Within the "Target:" field add %SystemDrive%\Windows\System32\cmd.exe /c to the beginning of the full path of your batch script.

  5. You can change the shortcut icon by selection the "Change Icon" button

  6. Click OK and right-click the shortcut and pin to your hearts' desire!

Note: Only local .EXE files have the Pin to... option. To get around this limitation, call on the engine or application that handles the file you are trying to open with a shortcut on the local system as I have done in step 4.

For a .VBS or .VBE file you may substitue %SystemDrive%\Windows\System32\cscript.exe //nologo in step 4. You can use this technique for practically any file type (I've only tested on Windows 7) to pin it to the Taskbar or Start Menu.

Questions are welcome. Happy scripting!


If you're curious about creating shortcuts from command-line check this out. This information would allow you to script the guide above. For this post I wanted to keep it simple.


r/dailyscripts • • Sep 16 '13

[bash/python] Automating the hell out of it

Thumbnail
gergely.imreh.net
8 Upvotes

r/dailyscripts • • Aug 23 '13

How to remotely shutdown Windows computers that are in a network via timed script or command prompt commands. No admin privlidges are given to me.

8 Upvotes

I will be working at the computer lab in my university as a lab monitor. One of my duties at the end of the night is to shut down all the computers. There are ~150 computers that I am responsible for and its a pain in the butt to turn them off indivisually. How would I automate this process? The only way that I know of is using the command prompt command <shutdown -i> but it needs admin privlidges.

Any help is appreciated


r/dailyscripts • • Jul 26 '13

[BATCH] go to your desktop

8 Upvotes

I spend a lot of time at a command line and because I have a habit of dumping things to my desktop I need to go there all the time. Now I have this very simple little batch file in my path on pretty much every system I touch (usually called desktop.bat). I end up using it at least once a day.

@echo off
c:
cd %HOMEPATH%\Desktop

r/dailyscripts • • Jul 25 '13

[AutoHotkey] 2nd simulated mouse cursor - best for multiple monitors and lazy people

Thumbnail
wikipacks.com
8 Upvotes

r/dailyscripts • • Apr 26 '23

I created an AI bot to explain changes made in a PR

7 Upvotes

I built this over a weekend because I had to review some painfully long pull requests (PR) at work (+2K) and I found myself skimming because I didn't want to think through that much code changes...

However, I still want to be a good steward of the codebase so with this at least I'm not gonna hate the process of code review as much. :)

It's free to use, you can check it out here: https://explainthispr.dev/

Cheers 🥳


r/dailyscripts • • Aug 30 '15

Latest automated task environment based on LUA! Kuppo!

7 Upvotes

Hey everyone, I never really posted this on reddit before and I found this little small community that I felt I could post it in. I have posted in a forum before but got 0 replies after months, and nobody seems interested in something such as this except in very "specific" communities.

Basically, over a year and a half ago I started working on what I would call a "Scar DIVI" replacement that is extremely easy to use. I always loved SCAR and other automated task programs that use scripting, but they were never documented in a way that lets a regular human use it.

Earlier this year I released version 0.95 and I've just finished up version 0.99. Completely reprogrammed including a new UI. I am really proud of it because so far as I have experienced very little bugs or problems as I went through months of perfecting and making sure it works correctly.

KUPPO is basically LUA with a layer of tools added on top of it that can be used to automate tasks. Tools such as a bitmap finder, pixel checker, simulated mouse and key presses, human-like mouse movement(using heavy math), and much more. Every single feature in KUPPO is documented in a single PDF that is only a few pages long. I can write a script in it that allows me to automate simple to complex things such as finding music on youtube or autoplaying the next netflix episode.

It is completely free of course as I never charge anything for any programs I develop.

You can download it here at my dev page KUPPO or just DevHotIssue

Also! I will be here to assist anyone with Kuppo, I can help you write your scripts and do error checking for you! I can teach or answer anything you need to know about it just ask away.


r/dailyscripts • • Mar 28 '14

How can I write a script to send random images from my library of 100,000 dick pics (don't ask) to a guy who keeps harassing my friends on Kik? Is there a way to send all 100,000 in an hour?

7 Upvotes

r/dailyscripts • • Jan 23 '14

[AutoHotKey] Make whole window transparent

7 Upvotes

Found this one here. There are tons of great AHK scripts on that page, but I liked this one the best. This is what the author said:

I call this script "TransparentWindow". If you press Ctrl+Alt+D (which I have bound to an extra button on my mouse), it will bring up a small dialog which has a slider which controls the opacity of the window currently underneath the mouse, and a checkbox which enables "Always on top" for the current window.

If you move your mouse away from the TransparentWindow dialog, then it will fade away after 3 seconds.

If you fade a window all the way out, it hides the window entirely. If you lose the TransparentWindow dialog, you can right click on the system tray icon, where there is an option to "Remove transparency from all windows".

Enabling the "Top" checkbox in the TransparentWindow dialog makes a window always on top until you bring up the TransparentWindow dialog again and clear it.

EDIT: Corrected the script. On line 102 there was an extra return. This caused the script to throw an error. The new Pastebin.com link should be the correct code. Thanks /u/neobot for pointing that out! - 23.1.2014