Navigation

Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

12/04/2019

google script to send SMS

Have a google form, and on submit, want google script to send text message.  In my case, it is one fixed cell phone, so I can do it for free by using email to SMS gateway.


Just substitute a 10-digit cell number for ‘number’ for each carrier below:
  • AT&T: number@txt.att.net (SMS), number@mms.att.net (MMS)
  • T-Mobile: number@tmomail.net (SMS & MMS)
  • Verizon: number@vtext.com (SMS), number@vzwpix.com (MMS)
  • Sprint: number@messaging.sprintpcs.com (SMS), number@pm.sprint.com (MMS)
  • XFinity Mobile: number@vtext.com (SMS), number@mypixmessages.com (MMS)
  • Virgin Mobile: number@vmobl.com (SMS), number@vmpix.com (MMS)
  • Tracfone: number@mmst5.tracfone.com (MMS)
  • Metro PCS: number@mymetropcs.com (SMS & MMS)
  • Boost Mobile: number@sms.myboostmobile.com (SMS), number@myboostmobile.com (MMS)
  • Cricket: number@sms.cricketwireless.net (SMS), number@mms.cricketwireless.net (MMS)
  • Republic Wireless: number@text.republicwireless.com (SMS)
  • Google Fi (Project Fi): number@msg.fi.google.com (SMS & MMS)
  • U.S. Cellular: number@email.uscc.net (SMS), number@mms.uscc.net (MMS)
  • Ting: number@message.ting.com
  • Consumer Cellular: number@mailmymobile.net
  • C-Spire: number@cspire1.com
  • Page Plus: number@vtext.com


20somethingfinance.com/

8/21/2017

determing Windows version via BAT script

Need to determine which version of Windows on laptops via CMD file:



for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
 
ECHO   %version% 


@echo off
for /f "tokens=4-7 delims=[.] " %%i in ('ver') do 
     (if %%i==Version (set v=%%j.%%k) else (set v=%%i.%%j)) 
 
if %v% == "10.0" goto  Win10

if %v% == "6.1" goto  Win7


:Win7
echo   Windows 7
goto exit

:Win10
echo   Windows 10
goto exit


:exit
pause

6/07/2017

IP printing script - Windows





Want to run BAT file to install IP printer on laptop:


CLS
@ECHO off

SET varIP=192.168.0.200
SET varDriver=HP Color LaserJet CP2020 Series PCL 6
SET varDriverFolder=\\Server\\Software\\Hardware\\Drivers\\Printers\\HP CP2025DN\\
SET varDriverFile=\\Server\\Software\\Hardware\\Drivers\\Printers\\HP CP2025DN\\hppcp610.inf
SET varName=Reception
SET varLocation=Reception

REM "Deleting TCP/IP port"
REM CSCRIPT /nologo %windir%\system32\prnport.vbs -d -r IP_%varIP%

REM "Creating TCP/IP port"
CSCRIPT /nologo %windir%\system32\prnport.vbs -a -r IP_%varIP% -o raw -n 9100 -h %varIP%

CLS
REM "Installation message"
@ECHO.
@ECHO The %varLocation% printer is currently being installed.
@ECHO.
@ECHO Please do not close this window.
@ECHO.
@ECHO Once the installation is complete this Setup window will exit.
@ECHO.

REM "Driver installation"
CSCRIPT /nologo %windir%\system32\prndrvr.vbs -a -m "%varDriver%" -h "%varDriverFolder%" -i "%varDriverFile%"  
CLS

REM "Printer deletion"
@ECHO.
@ECHO Completing installation.
CSCRIPT /nologo %windir%\system32\prnmngr.vbs -d -p "%varName%" 
CLS

REM "Printer installation"
@ECHO.
@ECHO Completing installation.
CSCRIPT /nologo %windir%\system32\prnmngr.vbs -a -p "%varName%" -m "%varDriver%" -r "IP_%varIP%"
CLS

REM "Location configuration"
@ECHO.
@ECHO Completing installation.
CSCRIPT /nologo %windir%\system32\prncnfg.vbs -t -p "%varName%" -l "%varLocation%"
CLS
 
 
 
 
https://community.spiceworks.com/ 

5/16/2017

auto login for Putty telnet

We use Putty software to telnet into a linux server, to setup autologin, create BAT file with following commands:


@echo off
putty -load "host" -l username -pw password


From stackoverflow.com

Also take a look at Putty tips & tricks

2/17/2017

javascript search box

Mark.js is a text highlighter written in JavaScript. It can be used to dynamically mark search terms or custom regular expressions and offers you built-in options like diacritics support, separate word search, custom synonyms, iframes support, custom filters, accuracy definition, custom element, custom class name and more.

https://markjs.io/     Examples

Here is a version that will allow you to jump to matching text   

7/31/2015

script to install print queues



rundll32 printui.dll,PrintUIEntry /u /in /n \\ntsrva\LAW228_HP




http://blogs.technet.com/b/askperf/archive/2011/09/16/print-queue-scripting.aspx

7/23/2015

automated Word index

The vb script below will create an index of every word from a document,  (directions for setting up macros)




Sub ConcordanceBuilder()
Application.ScreenUpdating = False
Dim StrIn As String, StrOut As String, StrTmp As String, StrExcl As String
Dim i As Long, j As Long, k As Long, l As Long, Rng As Range
'Define the exlusions list
StrExcl = "a,am,an,and,are,as,at,b,be,but,by,c,can,cm,d,did," & _
          "do,does,e,eg,en,eq,etc,f,for,g,get,go,got,h,has,have," & _
          "he,her,him,how,i,ie,if,in,into,is,it,its,j,k,l,m,me," & _
          "mi,mm,my,n,na,nb,no,not,o,of,off,ok,on,one,or,our,out," & _
          "p,q,r,re,s,she,so,t,the,their,them,they,this,t,to,u,v," & _
          "via,vs,w,was,we,were,who,will,with,would,x,y,yd,you,your,z"
With ActiveDocument
  'Get the document's text
  StrIn = .Content.Text
  'Strip out unwanted characters. Amongst others, hyphens and formatted single quotes are retained at this stage
  For i = 1 To 255
    Select Case i
      Case 1 To 35, 37 to 38, 40 To 43, 45, 47, 58 To 64, 91 To 96, 123 To 127, 129 To 144, 147 To 149, 152 To 162, 164, 166 To 171, 174 To 191, 247
      StrIn = Replace(StrIn, Chr(i), " ")
    End Select
  Next
  'Delete any periods or commas at the end of a word. Formatted numbers are thus retained.
  StrIn = Replace(Replace(Replace(Replace(StrIn, Chr(44) & Chr(32), " "), Chr(44) & vbCr, " "), Chr(46) & Chr(32), " "), Chr(46) & vbCr, " ")
  'Convert smart single quotes to plain single quotes & delete any at the start/end of a word
  StrIn = Replace(Replace(Replace(Replace(StrIn, Chr(145), "'"), Chr(146), "'"), "' ", " "), " '", " ")
  'Convert to lowercase
  StrIn = " " & LCase(Trim(StrIn)) & " "
  'Process the exclusions list
  For i = 0 To UBound(Split(StrExcl, ","))
    While InStr(StrIn, " " & Split(StrExcl, ",")(i) & " ") > 0
      StrIn = Replace(StrIn, " " & Split(StrExcl, ",")(i) & " ", " ")
    Wend
  Next
  'Clean up any duplicate spaces
  While InStr(StrIn, "  ") > 0
    StrIn = Replace(StrIn, "  ", " ")
  Wend
  StrIn = " " & Trim(StrIn) & " "
  j = UBound(Split(StrIn, " "))
  l = j
  For i = 1 To j
    'Find how many occurences of each word there are in the document
    StrTmp = Split(StrIn, " ")(1)
    While InStr(StrIn, " " & StrTmp & " ") > 0
      StrIn = Replace(StrIn, " " & StrTmp & " ", " ")
    Wend
    'Calculate the number of words replaced
    k = l - UBound(Split(StrIn, " "))
    'Update the output string
    StrOut = StrOut & StrTmp & vbTab & k & vbCr
    l = UBound(Split(StrIn, " "))
    If l = 1 Then Exit For
    DoEvents
  Next
  StrIn = StrOut
  StrOut = ""
  For i = 0 To UBound(Split(StrIn, vbCr)) - 1
    StrTmp = ""
    With .Range
      With .Find
        .ClearFormatting
        .Text = Split(Split(StrIn, vbCr)(i), vbTab)(0)
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
      End With
      Do While .Find.Found
        StrTmp = StrTmp & " " & .Information(wdActiveEndPageNumber)
        .Collapse (wdCollapseEnd)
        .Find.Execute
      Loop
    End With
    StrTmp = Replace(Trim(StrTmp), " ", ",")
    StrOut = StrOut & Split(StrIn, vbCr)(i) & vbTab & StrTmp & vbCr
  Next
  'Create the concordance table on a new last page
  Set Rng = .Range.Characters.Last
  With Rng
    .InsertAfter vbCr & Chr(12) & StrOut
    .Start = .Start + 2
    .ConvertToTable Separator:=vbTab, Numcolumns:=3
    .Tables(1).Sort Excludeheader:=False, FieldNumber:=1, _
      SortFieldType:=wdSortFieldAlphanumeric, _
      SortOrder:=wdSortOrderAscending, CaseSensitive:=False
  End With
End With
Application.ScreenUpdating = True
End Sub






From   microsoft.com Answers


7/15/2015

Validating user input from batch file

To prevent blank input:



:askQuestion
set /p UserName=   What is your CUA user ID? || Set UserName=NothingChosen

If "%UserName%"=="NothingChosen" goto :sub_error
:sub_error
echo Error:   Please type in CUA user ID
echo(
echo(

goto:askQuestion


To use regular expression:


:loop
    SET /P "UserName=What is your CUA user ID?: "
    echo("%UserName:"= %"|findstr /r /C:"""[0-9][0-9][a-zA-Z]*""" >nul || ( echo Error:   CUA user ID starts with 2 digits & ECHO( & goto loop )

7/14/2015

Installing windows print queue on laptop

To install printers on student laptops (not on domain) the START command works best:


echo Starting printer install....
start \\printers.cua.edu\LAW150_HP4000



This will just like manual install, and will generate Windows Security popup, student must put in user name preceded by domain, and then password:

DOMAIN\userName


This will save name/password in Credentials Manager.



To install via Visual basic, computer must be on the domain:



Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\printers.cua.edu\LAW400_HP9000"



7/13/2015

Open URL with CMD file

What to open web page, and submit form via CMD script:



set /p UserName=   What is your CUA user ID? 
echo(

start ""  http://test.law.cua.edu/form/printer-install.asp?name=%UserName%^&explanation=Library_Prnt_v3b^&OS=Windows^&Submit=Submit"


The URL has variable, enclosed by %  %,  and &'s which must be escaped via ^

http://test.law.cua.edu/form/printer-install.asp.asp?name=%UserName%&explanation=Library_Prnt_v3b&OS=Windows&Submit=Submit"

1/15/2015

Visual basic to access CMD or Shell commands

Wanted to run CMD   NET USER /DOMAIN  
from vb script, and return password expiration date:



Dim objShell, objWshScriptExec, objStdOut, strLine, bolFoundFlag
bolFoundFlag = FALSE

Set objShell = CreateObject("WScript.Shell")
'Set objWshScriptExec = objShell.Exec("ipconfig /all")
Set objWshScriptExec = objShell.Exec("NET USER /DOMAIN " & strName)

Set objStdOut = objWshScriptExec.StdOut

While Not objStdOut.AtEndOfStream
   strLine = objStdOut.ReadLine
   ' english windows
   If InStr(strLine,"Password expires") Then
       response.Write(strName & ":&nbsp;&nbsp; " & strLine & "<p>")
       bolFoundFlag = TRUE
   ' french windows      
   ElseIf InStr(strLine,"found") Then
      response.Write( strLine & "<p>")  
   End If
  
'   response.Write(strLine & " <br>")
Wend

11/19/2014

Using lpadmin command on Yosemite OS

I had Applescript with LPADMIN command that worked with Apple OS, but stopped working on Yosemite (10.10).  Did not get any error, the printer always was in paused state.


 From macenterprise on Google Groups:

I'm seeing some strange cases at the university where certain users are unable to print authenticated via smb when on Yosemite.

I had just about weaned our users off of unauthenticated lpd when printing to our Windows print server in favor of smb with their credentials stored pr. printer in the keychain.

There doesn't seem to be a pattern to who it affects but there are indications that it's sandbox related (cryptic log messages and the like)

Putting the "Sandboxing relaxed" directive in /etc/cups/cups-files.conf seems to fix it for some.

Has anyone else seen problems when printing to smb printers on Yosemite?

Regards,

Simon Andersen
Aarhus University, Denmark

REPLY:



Tony Skalski

Oct 29
Other recipients: MACENT...@lists.psu.edu
We added "-o auth-info-required=negotiate" to our lpadmin command in the
install script we package up for students to use. This seems to have fixed
the Yosemite printing issues we've seen.

ajs
Tony Skalski
Systems Administrator
St. Olaf College
Information Technology
1510 St. Olaf Avenue


-----------------------------------------------------

Poster in Stackoverflow suggested a fix was to add  -E  to enable at the very end, this did NOT work for me.

do shell script "/usr/sbin/lpadmin  -L '3rd-floor-library'   -o printer-is-shared=false -o Duplex=DuplexTumble -o Option1=True -p  '3rd-floor-library' -v smb://server1.cua.edu/LAW_HP9050 -P   " & quoted form of (POSIX path of myFile) as text & "  -E"

Previously I did not need the -E switch.   Adding printer via Printers and Scanners UI works fine under Yosemite, just adding it via lpadmin broke under Yosemite.

From Apple:
-E            Enables the destination and accepts jobs;


From Stackoverflow

8/19/2014

Applescript: lpadmin command to set duplexing

Wanted to use LPADMIN command to turn on duplexing when I installed printers, I am using Generic PCL printer driver, version 1.3


First use this command to get options:
lpoptions -p printer_name -l
 
This returned:
 
PageSize/Media Size: *Letter Legal Executive Tabloid A3 A4 A5 B5 EnvISOB5 Env10 EnvC5 EnvDL EnvMonarch
Resolution/Resolution: *300dpi 600dpi
InputSlot/Media Source: *Default Tray1 Tray2 Tray3 Tray4 Manual Envelope
Duplex/2-Sided Printing: *None DuplexNoTumble DuplexTumble
Option1/Duplexer: *False True
 
 
So need to add this to lpadmin commandline:
-o Duplex=DuplexTumble -o Option1=True 
 
Full statement is:
do shell script "/usr/sbin/lpadmin  -L 2nd-floor-library    
 -o printer-is-shared=false  -o Duplex=DuplexTumble -o Option1=True 
 -p  '2nd-floor-library' -v smb://testserver.someplace.edu/LAW228_HP600 -P   
 " & quoted form of (POSIX path of myFile) as text & "  " 
 


This does not make double sided printing the default, rather it makes sure the option is not grayed out, and that 2 sided printing can be selected.

6/19/2014

Applescript: Keychain add/delete


Security command syntax, from Apple Developer pages.



http://macscripter.net/viewtopic.php?id=36818

security add-internet-password  -a cua\\\\userName  -l '2nd-floor'  -s ntsrva.cua.edu   -p LAW228_PRINTER_QUEUE   -r 'smb '  -w  Password  -D 'network password'  -A



add-internet-password [-h] [-a account] [-s server] [-w password] [options...] [keychain]
            Add an internet password item.

            -a account      Specify account name (required)
            -c creator      Specify item creator (optional four-character code)
            -C type         Specify item type (optional four-character code)
            -d domain       Specify security domain string (optional)
            -D kind         Specify kind (default is "application password")
            -j comment      Specify comment string (optional)
            -l label        Specify label (if omitted, service name is used as default label)
            -p path         Specify path string (optional)
            -P port         Specify port number (optional)
            -r protocol     Specify protocol (optional four-character SecProtocolType, e.g. "http", "ftp ")
            -s server       Specify server name (required)
            -t authenticationType
                            Specify authentication type (as a four-character SecAuthenticationType, default
                            is "dflt")
            -w password     Specify password to be added
            -A              Allow any application to access this item without warning (insecure, not recom-mended!) recommended!)
                            mended!)
            -T appPath      Specify an application which may access this item (multiple -T options are
                            allowed)
            -U              Update item if it already exists (if omitted, the item cannot already exist)

            By default, the application which creates an item is trusted to access its data without warning.
            You can remove this default access by explicitly specifying an empty app pathname: -T "". If no
            keychain is specified, the password is added to the default keychain.
 
 
 delete-internet-password [-h] [-a account] [-s server] [options...] [keychain...]
            Delete an internet password item.

            -a account      Match account string
            -c creator      Match creator (four-character code)
            -C type         Match type (four-character code)
            -d securityDomain
                            Match securityDomain string
            -D kind         Match kind string
            -j comment      Match comment string
            -l label        Match label string
            -p path         Match path string
            -P port         Match port number
            -r protocol     Match protocol (four-character code)
            -s server       Match server string
            -t authenticationType
                            Match authenticationType (four-character code) 

6/16/2014

Applescript: administrator privileges




How do I get administrator privileges for a command?

Use the administrator privileges, user name and password parameters like this:
 
do shell script "command" user name "me" password "mypassword" with administrator privileges

user name and password are optional; if you omit the user name, do shell script assumes it to be the current user; if you omit the password, it will ask for a password when it runs. Once a script is correctly authenticated, it will not ask for authentication again for five minutes. As of Mac OS X 10.4, this grace period does not extend to any other scripts or to the rest of the system;

6/10/2014

Applescript: installing windows print queue


Looking to install windows print queue on Apple OS via Apple script

This is path, with the username/password embedded
smb://domain\\\\userName:Password@server.address.edu/queueName

do shell script "/usr/sbin/lpadmin -p  3rd-floor -v smb://CUA\\\\" & userName & ":" & ThePassword & "@server.address.edu/queueName -P   " & quoted form of (POSIX path of driver3) as text & "  -D \"3rd-Floor-Library\""

do shell script "sudo /usr/sbin/accept 3rd-floor" with administrator privileges
   This sets correct access or right for the printer.


I embedded username/password because I found issues trying to use Applescript to create entries in Keychain.


lpadmin switches


 -L "location"
            Provides a textual location of the destination.

 -P ppd-file
            Specifies  a  PostScript  Printer  Description  file to use 
            with the printer. If specified, this
            option overrides the -i option (interface script). 
 
 -v "device-uri"
            Sets the device-uri attribute of the printer queue. 
            Use the -v option with the lpinfo(8) command
            to get a list of supported device URIs and schemes.

 -D "info"
            Provides a textual description of the destination. 

4/14/2014

visual basic script to create URLs from a file directory

create file with .VBS extention, and then double click to run and create the output file with the URLs.


'2014-04 Len Davidson
'
'

On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder

Set fso = CreateObject("Scripting.FileSystemObject")

' this code would take argument for folder name, I hardcode it below
' sFolder = Wscript.Arguments.Item(0)
' If sFolder = "" Then
' Wscript.Echo "No Folder parameter was passed"
' Wscript.Quit
' End If

sFolder = "folder-name-here"

Set NewFile = fso.CreateTextFile(sFolder&"\FileList.txt", True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files

For each folderIdx In files
'  only want to include PDF files
If InStr(folderIdx.Name, ".pdf") > 0 Then
NewFile.WriteLine("http://your-server.com/mockup/test1/uploading/" & sFolder & "/" & folderIdx.Name)
end if
Next
NewFile.Close



Source

4/09/2014

Generating URLs from a list of files in a directory

This code will take file names from a directory (eg all mp3 files) and create a URL in an output file.txt





REM dir /B  > AAoutputURLs.txt
REM for /d %%A in (*.mp3) do echo ^<root^>^<dir^>%%~A^</dir^>^</root^> >> AAoutput1.txt

REM "cmd /c  echo   Unless you have opted out, the Law Library posts URL links to the “Class Recordings” list located at http://columbo.law.cua.edu/search/r?SEARCH=class.  Access to the URL links is restricted to current CUA law students only.   >> AAoutput1.txt"

REM "cmd /c  echo If you wish to post your specific URL link(s) onto your TWEN webpage, please include the alert message for Mac users.  Thank you.  >> AAoutput1.txt"


forfiles /M *.mp3  /C "cmd /c  echo http://136.242.14.49/law.cua.edu/academicexcellence/2014Spring/@file>> AAoutput1.txt"
REM forfiles /M *.mp4  /C "cmd /c  echo http://136.242.14.49/law.cua.edu/academicexcellence/2014Spring/@file>> AAoutput1.txt"
forfiles /M *.wmv  /C "cmd /c  echo http://136.242.14.49/law.cua.edu/academicexcellence/2014Spring/@file>> AAoutput1.txt"

REM  next line puts in date
echo %date:~4,10% >> AAoutput1.txt
echo( >> AAoutput1.txtpause

1/17/2014

Create hyperlinks in Excel

To create hyperlinks in an Excel column, use the macro below:


Public Sub Convert_To_Hyperlinks()
Dim Cell As Range
For Each Cell In Intersect(Selection, ActiveSheet.UsedRange)
If Cell <> "" Then
ActiveSheet.Hyperlinks.Add Cell, Cell.Value
End If
Next
End Sub

Creating the Macro

  • Open your Excel doc
  • Open the macro editor by pressing ALT+F11.
  • In the Tools Menu, left-click View and select Project Explorer.
  • Look for the folder called ‘Modules’, right-click it, select ‘Insert’, then select ‘Module’.
  • Paste the code into the project module you have selected.
  • Press ALT+F11 to return to your Excel workbook (or click on its icon in the Windows taskbar).

Run the Macro

  • To execute the macro, select the unclickable text links you want to convert to clickable hyperlinks.
  • Press ALT+F8 to open the Macro selector window and click on the macro you just created.
  • Your Links are now all Clickable! Saving you time and data entry fatigue :)

Note:  must save this as extension XLSM, because it has macro (xlsx is non macro enabled spreadsheet)

From:  http://www.niallflynn.com/random-news/convert-urls-to-clickable-links-in-excel/

9/21/2012

VBA code to ESC from Access Form entry

In Microsoft Access 2010 database, wanted to create button that did same as pressing ESC key;

Found blog post on Use code to "undo" things in Access 

DoCmd.RunCommand acCmdUndo

If there is nothing in the form, nothing can be UNdone, get error 2046.  Added error handling,  just close the form, and exit the subroutine.


Private Sub Button_Click()
On Error GoTo ErrorHandler
DoCmd.RunCommand acCmdUndo
DoCmd.Close acForm, "Faculty Purchases - FY 2012", acSaveYes
Exit Sub
ErrorHandler:

Select Case Err

         Case 2046:    ' Error 2046: "Nothing can be UNDOne"
                       
         DoCmd.Close acForm, "Faculty Purchases - FY 2012", acSaveYes
         Exit Sub
        
         Case Else:      ' An error other than 2046 has occurred.
            ' Display the error number and the error text.
            MsgBox "Error # " & Err & " : " & Error(Err)

      End Select
End Sub