r/ScriptSwap • • Feb 20 '16

Service management script for Mac OS X (similar to "service" on linuxes)

4 Upvotes

https://github.com/ScoreUnder/mac-service

Born out of mild frustration with Mac OS X's launchctl commands. Tested to work on OS X 10.9 (Mavericks) and 10.10 (Yosemite). If it's not working on your version please poke me about that!

Mostly this is just a sugary wrapper to report things like failure launching, provide status info for a service, and allow restarting.

I'm planning to use this in my day-to-day OS X sysadmin work, because I find service a lot easier to work with than launchctl.


r/ScriptSwap • • Mar 21 '15

[sh] pause cmus-player when something else is playing

4 Upvotes

A small script to pause cmus when something else is playing (or opens the device). With fading in and out (primitive, via softvol and sleep, but working for me). cmus must be started prior to the script. It only works with alsa and you will need the inotify-tools as well as the procps utils.

http://pastebin.com/RHDQ5ZUG (public domain)


r/ScriptSwap • • Mar 11 '15

[sh] luks-helper.sh - create, mount and unmount LUKS encrypted container files

4 Upvotes

https://github.com/nodiscc/scriptz/blob/master/sysadmin/luks-helper.sh

I needed file-level encryption (not device-level), and was stuck with encfs which has some known vulnerabilities and is less practical on some aspects (many files instead of a single one). This script does a good job. Needs root/sudo though.


r/ScriptSwap • • Jan 14 '15

[bash] pg() a simple paging function

4 Upvotes

Unlike simply using less or cat, this function decides between the two based on how many lines of output there will be and takes into account the number of screen lines taken by the PS1 prompt. It uses fmt to wrap long lines without re-flowing paragraphs.

#======================================================================
# Format a file and display it or page it if necessary
#======================================================================
pg () {
declare promptLines=$(echo -e "$PS1" | wc -l)
fmt -s -w $COLUMNS "$1" |
if [[ $(fmt -s -w $COLUMNS "$1" | wc -l) -gt $(( LINES - promptLines )) ]]; then
    less
else
    cat
fi
} 2>/dev/null

r/ScriptSwap • • Jun 07 '14

[Javascript[NodeJS]] Share your clipboard with friends and strangers

4 Upvotes

Whenever I use SSH, I often get frustrated because I often want to share the clipboard between my computer and remote computer. So I wrote this tiny JS script that works as follows and can be run with node.

GET requests return the content of the clipboard in the response body POST requests copy the request body to the clipboard

The code is as follows:

var spawn = require('child_process').spawn;
var http  = require('http');

function handleRequest(request, response) {
  if (request.method == 'POST') {
      var body = '';
      request.on('data', function (data) {
          body += data;
          if (body.length > 1e6)
              req.connection.destroy();
      });
      request.on('end', function () {
          var pbcopy = spawn('pbcopy');
          pbcopy.stdin.write(body); pbcopy.stdin.end();
          var notify = spawn('terminal-notifier', ['-message', 'A message has been copied to your clipboard.']);
          response.writeHead(200, {'Content-Type': 'text/plain'});
          response.end(body);
      });
  } else {

    var content = '';
    var pbpaste = spawn('pbpaste');

    pbpaste.stdout.on('data', function(data){
      content += data;
    });

    pbpaste.stdout.on('end', function(){
      response.writeHead(200, {'Content-Type': 'text/plain'});
      response.end(content);
    });
  }
}

http.createServer(handleRequest).listen(1337);

To copy:

curl {your-ip}:1337

To paste from standard input:

curl -XPOST {your-ip}:1337 --data-binary @-

If you alias the above commands as scripts zcopy and zpaste respectively, then they will function almost exactly like pbcopy and pbpaste.

Also, note that this is only possible if the remote computer can connect to your computer directly as well, so it will not work if you are behind a firewall (although I think you could do remote ssh port forwarding to accomplish this).

This script only works on Mac OS X because it uses pbcopy and pbpaste, but could easily be modified to work with other clipboard systems. And it also uses the terminal-notifier application to send notifications when something is placed on your clipboard. This is available here: https://github.com/alloy/terminal-notifier

Also, if anyone knows of a better way to do clipboard sharing, let me know! I was thinking there may be a better solution, but I was not certain.


r/ScriptSwap • • Nov 15 '12

[bash] add ssh key to remote server for no pw prompt when using ssh, scp, rsync

4 Upvotes

https://github.com/stgnet/bin/blob/master/sshkey

#/bin/sh
# install key on remote server for no-password login

SERVER="$1"
[ -z "$SERVER" ] && echo -n "Enter server or user@server: " && read SERVER
USER="${SERVER%@*}"
[ "$USER" = "$SERVER" ] && USER="root"
SERVER="${SERVER#*@}"
[ -z "$USER" ] && USER=`whoami`

# generate our local key
[ ! -d ~/.ssh ] && mkdir -p ~/.ssh
[ ! -f ~/.ssh/id_dsa.pub ] && ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

IAM="`whoami`@$HOSTNAME"

echo "Installing ssh key for $IAM on $USER@$SERVER"
ssh $USER@$SERVER "mkdir -p ~/.ssh;[ -f ~/.ssh/authorized_keys ] && sed -i "/$IAM/d" ~/.ssh/authorized_keys;cat >>~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys" <~/.ssh/id_dsa.pub

r/ScriptSwap • • Oct 19 '12

[bash] directory browser and bookmarks manager

4 Upvotes

DirT

Here's this thing I built to manage directory bookmarks in bash. It's a considerably more heavy-weight solution to the same issues addressed by pushd/popd and the directory hopper and so many others, but this one is mine.

Just thought I'd share.

[edit: spelling]


r/ScriptSwap • • Oct 18 '12

[bash] Script for creating pull requests on GitHub

4 Upvotes

I've got a simple script we're using at work to create pull requests on GitHub for code review purposes:

https://gist.github.com/2820032

It certainly lacks ability to create pull requests to another repo - if you're a contributor and can push only to your fork, script won't create pull request to original repo.

But I don't create that much pull requests to open source projects as I do for my work projects, so this wasn't a problem for me. :)


r/ScriptSwap • • Mar 30 '12

Web crawler written in Lisp

4 Upvotes

I have been learning for a bit now but am still a beginner. It's in Scheme by the way, and only works if your system has the program 'curl' installed. It runs really, really slowly. But it works! Here is the source code:

http://pastebin.mozilla.org/1617482


r/ScriptSwap • • Mar 16 '12

[zsh] play flash video in mplayer

4 Upvotes

basically it if you are playing something in flash somewhere, and want to play it in mplayer (while leaving it streaming) run this, and mplayer will open it. only works with firefox

#!/bin/zsh

fpid=$(pidof plugin-container)

fd=$(lsof | grep $fpid | /bin/grep '(deleted)' | /bin/grep FlashX |  /bin/grep -o '[0-9]*u ' | head -1)


if [[ -z $fd ]];then

    fpid=$(pidof firefox)

    fd=$(lsof | grep $fpid | /bin/grep "media_cache" |  /bin/grep -o '[0-9]*u ' | head -1)

fi

fd=$fd[1,-3]

print /proc/$fpid/fd/$fd 

#echo /proc/$fpid/fd/$fd | xclip -i

[[ -n $1 ]] && exit

mplayer  /proc/$fpid/fd/$fd

link here for wget


r/ScriptSwap • • Mar 02 '12

Back up a large directory to multiple DVDs.

4 Upvotes

Great for backing up music or photos or "photos."

#!/bin/bash

#########################################################
# dir2dvd.sh						#
#							#
# Requirements:						#
# find, du, zenity, growisof				#
# Requires a partition with $DS kilobytes available.	#
#########################################################

DVD=/dev/dvdrw
function burnit {
	YY=""
	read YY
	if [ ! YY = "skip" ]
	then
		/usr/bin/growisofs -Z $DVD -speed=4 -v -R -l $CD/
	fi
}

function removem {
	echo "Removing files..."
	find $CD/ -type f -exec rm {} \;
	touch $CD/$LASTDIR/file.out
	echo "Removing directories..."
	find $CD -depth -type d -empty -exec rmdir {} \;
	rm $CD/$LASTDIR/file.out
	eject cdrom
}

PWD=`pwd`

# BD=/home/mp3
# CD=/2home/mp3
BD=/home/user
CD=/tmp/dir

cd $BD

DS=4300000
#DS=4590208

A=0
X=0

DISC=1

LIST=`find . -print | grep -v dir2dvd.sh | cut -c3- | sort -n`

DU=`du -sk $BD | cut -f1`
COUNT=`expr $DU / $DS`

echo "Photo backup will require `expr $COUNT + 1` discs."

ifs=$IFS

IFS='\
'

FILELIST=dvdfile.list
> $HOME/$FILELIST

for i in $LIST
do

#	Check to see if the LIST element is a directory.  If yes,
#	create the directory.
	if [ -d $i ]
	then
		mkdir $CD/$i
		LASTDIR=$i
	else

#		Check if the size count A is less then the DVD space.  If
#		yes, add the next file size to A, copy the file to the
#		directory, add the file to a file list, keep track of the
#		number of files copy, then give a progress message.  Else,
#		write the DVD then remove the files, add a file to keep the
#		current last directory, remove the empty directories, then
#		continue.
		if [ $A -lt $DS ]
		then
			((A=$A + `du -sk $i | cut -f1`))
			cp -r $i $CD/$i
			echo "Disc $DISC: $i" >> $HOME/$FILELIST
			echo "Disc $DISC: $i" >> $CD/$FILELIST
			((X=$X + 1))
			if [ `expr $X % 100` -eq 0 ]
			then
				echo "Kilobytes: " $A " Files: " $X " File: " $i
			fi
		else
			zenity --text "dir2dvd.sh
	
			Please insert Disc $DISC blank DVD.
			Click OK to continue" --info

			echo -n "Insert Disc $DISC DVD. Going to burn DVD, press     enter:"
			burnit
			A=0
			X=0
			removem
			((DISC=$DISC + 1))
		fi
	fi
done

#	Burn the remaining files that didn't fill to the $DS limit.
zenity --text "dir2dvd.sh

Please insert the last Disc $DISC blank DVD.
Click OK to continue" --info

echo -n "Insert the last Disc $DISC DVD. Going to burn DVD, press enter:"
burnit

removem

IFS=$ifs

cd $PWD

r/ScriptSwap • • Jun 26 '24

Made a little script to automatically update Discord on run for Debian distros

3 Upvotes

Hi everyone, just as the title says because it was getting on my nerves. Probably there are other scripts out there but here is mine.

https://gist.github.com/sgatu/d60072d8afefcd50ab37b3f0a7e5660b


r/ScriptSwap • • Apr 04 '24

Script for my wife

3 Upvotes

This may sound silly, but my wife has a membership at a very niche spin studio and if you don’t login at exactly 12 o’clock noon to register for the following days class, you’ll end up on like a 10 person waitlist and never get a bike. Is it possible to write a script that would automatically register her for her desired class and time at exactly 12 noon?


r/ScriptSwap • • Jan 22 '24

Script for Google Sheets

3 Upvotes

I have made a project-template-bundle of files that contain formulas so that different files reference one another. These are all contained in a "Template folder"

To start a new project, I want to do a “pack and go” of the template folder. In other words, I want to create a copy of the folder containing these templates and start working on a new project inside that New Project folder by filling out the copied files. This means that the files in the New Project folder should reference each other via formulas without referencing the files in the Template folder that the copy was made from. Is there a script for achieving this? I've been looking but ended up empty handed. Unfortunately I have no coding experience.


r/ScriptSwap • • Jan 15 '24

I wanna make a script that dose a mouse click when noise is heard

3 Upvotes

Ok I’m a beginner so I might need it on a free scripting software and much help is needed thank you!


r/ScriptSwap • • Sep 19 '23

Need a script to Change a Group Policy Setting

3 Upvotes

Does anyone know if it's possible to make a script that changes the group policy setting ( delete user profiles older than a specific number of days on system restart ). I have to constantly change this setting individually on computers at work and would love to just run a script on each computer to to it automatically. I'd prefer to push this setting out over azure that would make my life easier, but for the sake of keeping this short, I can not do that at this current time. Any advice helps thank you.


r/ScriptSwap • • Jan 11 '21

Looking for some scripts to move files based on age

3 Upvotes

I am looking to have a generic script that I can put source-destination to be an archive so to speak. Logging would email the results upon completion using smtp relay. I am looking to be able to run this script as a scheduled task on as needed basis.

The initial test is I have a very large group of files and folders in a "quality" folder. I would like to have everything that is is 18months old move the files to the new directory and clean up the old one. My latest attempt moved the files but they were all 0bytes and all worthless. I was using robocopy /move to attempt this as a poc and it failed spectacularly. Scripting is a spot I am working on improving but data needs to be cleaned up now.


r/ScriptSwap • • May 15 '20

[scriptty.dev] a place where developers share their handy scripts

3 Upvotes

Hi folks!

Recently i was searching for a script that help me scrape data from a website so i start searching for it on github and i found some scrappers made by developers but it's take me some time to found the right one so i decided to make a simple website that will make this operation faster you can search for a script save it or add yours to help other developers out there.

So i invite you to add yours if you have some (automation scripts scrappers, converters ...) and if you have idea that you wish to add it to this app please feel free to email me [email protected] or dm me on twitter https://twitter.com/amine1bioudi.

 👇🏻 👇🏻 👇🏻 👇🏻

scriptty.dev


r/ScriptSwap • • Oct 16 '19

Money-making idea for Scripts, potential $100s per user.. Searching multiple phone numbers (of friends+family) in robocalling lawsuit

3 Upvotes

At any given time, there are several class action settlements active for illegal telemarketing. The FCC takes this very seriously and payouts can be $100+ per text/call.

Would anyone be interested in creating a script that automates querying of multiple phone numbers on these sites? That way one person can search for multiple friends+family.

I'm a newb here, but I imagine this:

2. inputting the URLs and tagging the correct field/entrybox

3. the user adds their list of phone numbers to their version of the script

3. the script automatically enters one # at a time, checking if the website responds with an atypical message

(the logic being that most numbers will not qualify, so the script only needs to check for an atypical result)

Here are some robocalling settlements that are searchable, if I get a response I'll update with more. I'm willing to continue listing these:

Thanks for your time

https://enagicsecureclaims.com/ClaimForm/Continue1 https://kccsecure.com/HotTopicTextMessageSettlement/Claimant/UnknownPhoneLookup

https://kccsecure.com/ohagencytelemarketingsettlement/Claimant/UnknownPhoneLookup

https://www.targettcpasettlement.com/Login BONUS: here's the link for class action rebates for products... for example if you bought Egyptian Cotton products recently, you can get a check for up to $10.50.. there are various rebates and many are no proof of purchase of required


r/ScriptSwap • • Aug 09 '19

VBS Script to unlock pc

3 Upvotes

So, forgive me if I'm in the wrong area for this, but...

I'm looking to make a vbs script that I can initiate from Remote Desktop Connection to unlock my pc AFTER terminating the RDC, which locks the pc...

Simply trying to avoid having to walk downstairs too much, with my legs recovering from an accident. Thank you in advance for any help provided...


r/ScriptSwap • • Feb 22 '19

Brainfart on script to convert html to txt/md HELP

3 Upvotes

# SOLVED I spoke too soon

So I made a little script to pull a webpage then convert to convert a webpage (blogs) into a txt/md file. You would only need to install lynx if you haven't already, I am having a small issue getting a variable to ... print?

I had print (URL) to verify the variable was saved correctly. But I cannot figure out how to call the variable in wget -O-...

additionally I would like to make <test> be the name of the article/blog/page. I presume parsed from URL, or truncated after the last / in (URL) .

#~ /bin/bash

URL = input("Enter a URL")

#print (URL)

f"wget -O- {URL} | lynx -dump -stdin > ~/Documents/name.txt"

Edit- I was halfway there, previous script had print "wget -O- (URL)... simply needed to change from parenthesis to curly brackets.

if you want to download to a "true" markdown format install pandoc and follow the directions in the pandoc section here. But I think this script is only printing the function, not "running" the function. If you type out the last string (minus f and insert a proper URL) you will get a txt file of the blog.


r/ScriptSwap • • Feb 09 '19

Download webpage as html everyday

3 Upvotes

Hi community! I'm looking for a script that could login in some webpages and dowload them as html. I'd need this tasks to be performed everyday (for example at a certain time or range its the same). If you have done sonething similar and wanna share how did it, i'd really appreciate it!


r/ScriptSwap • • Aug 13 '18

Making Templates with pdfs

3 Upvotes

Is there anyway to scan a paper form and then convert it to a word document template?

I have an average material list form counts/description/price/quantity/total that i want to recreate in word as template for employee with horrible handwriting.

bonus question: is it possible to writing a script that could take pricing sheets ( product code/name/quantity measurement sold in/price per unit) and upload into an excel sheet in specific column?


r/ScriptSwap • • May 31 '18

[OC][bash][csh] Alias command with fallbacks.

3 Upvotes

https://github.com/roguh/tryalias

I've been using this script to create an alias that checks if the given command exists, if it doesn't then it tries the fallbacks.

I use it to alias either exa -a or ls -a to l. I also "tryalias" my favorite text editors because I synchronize my aliases to machines provisioned with different editors. If none of the editors are found, the command sticks with the last option. For example:

tryalias v vis nvim vim vi elvis ex-vi 'emacs -nw' "emacsclient -nw --alternate-editor=''" nano ed gedit libreoffice openoffice "playonlinux --run 'Microsoft Powerpoint 2010'"` notepad.exe vim

r/ScriptSwap • • Feb 05 '18

VBS to remove a registry entry (need help fixing)

3 Upvotes

Hi everyone, can't get the script below remove a value called "SecurityHealth" from Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

THANK YOU!

'This script will delete Registry Value if it exists const HKEY_CURRENT_USER = &H80000001 const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_ strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" strValueName = "SecurityHealth" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then Wscript.Echo "The registry value does not exist." Else oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

End If