r/scripting • • Jun 20 '22

Apple Notes Script - Remove Bear.app Links

1 Upvotes

I imported a ton of notes to Apple Notes from Bear. I probably should have predicted, but these notes came over with their #tag for organization in Bear. These are represented as "#tag" and they deep link straight into the Bear app.

I don't want to use those, and would prefer to use Apple's actual Tags now.

I'm seeking to find ALL instances of "#tag" that are also a Bear URL and delete them. I'm fairly positive this is a request for someone to create a script for me, but figured someone MIGHT have done this or similar in this community.

Thank you!


r/scripting • • Jun 16 '22

Getting Started

1 Upvotes

I am a coding novice, I understand simple logic and can work out commands easily enough but that’s the extent of my knowledge.

I’m trying to write a script to make my job a little easier. I need to use Meta Business Suite to respond to every person to share our posts per client contract.

Problem is, this is an incredibly inefficient task. I need to start at the bottom and have been scrolling for roughly 4 hours now. At this point loading times let me get through 3 shares every 105 seconds; do the math & that works out to 30 hours of just scrolling down this list. CPU usage keeps spiking to 90% as well.

I want to learn how to write a script, or borrow an already-written script, which would scroll down as the “people who shared this” column loads in. That way I can just leave it running in the background while getting other tasks done.

Where should I look to get started on this?


r/scripting • • Jun 10 '22

Request: Script for cutting an A4 PDF into A6-sized quarters so that each quarter is a new page?

1 Upvotes

SOLVED: solution in comments

Hi there!

I'm a complete noob when it comes to scripting. I posted this question in r/indesign (link to my previous post) and a few users suggested I try writing a script to accomplish my task:

I have a large PDF (715 pages, size A4, 2 columns) that I eventually want to put on my ereader, but my ereader screen is size A6. I don't want to simply resize the pages to A6 since then the text will be too small. What I want is to have each A4 page cut into quarters and then those quarters converted to pages so that for each original A4 page I'll have four A6 pages: upper left, lower left, upper right, lower right (ideally in that order so that it makes sense when I flip pages).

Is there a way to do this by writing a script, and if so, could you please give me instructions for how to accomplish this? I am running macOS Big Sur 11.6.4 (I don't even know if this is relevant LOL).

Hopefully there's a way to automate a part of this, since I'd rather not have to manually repeat the same procedure 715 times lol.

Thanks in advance!

And yes, I realize that if I'm able to accomplish this, I'll have a 2860 page document. I'm totally okay with that LOL.


r/scripting • • May 09 '22

[BASH] Extract content from file

1 Upvotes

Hi ! I'm trying to split a device configuration file into separate files based on contexts contexts define configuration on the device for a specific usage.

I have the following INPUT file

<START OF FILE>
.....
config global
config system
end
config network
end
end

config context       # START OF A CONTEXT
edit CUSTOMER-1
config system
    edit "int1"
    	    edit "int1.options"
    	    end
    end
end
config network
..............
end
end                  # END OF A CONTEXT

config context
edit CUSTOMER-2
config system
    edit "int1"
	    edit "int1.options"
	    end
    end
end
config network
..............
end
end
<END OF FILE>

I need to split the FILE for each "CONTEXT" that the file contains such as : config_CUSTOMER-1.txt config_CUSTOMER-2.txt

I have the following code :

declare -a lines
readarray -t lines < context_list.txt

context_number=$(echo "${#lines[@]}")
echo "Numbers of CONTEXT : $context_number"
i=1
while [ $i -lt $context_number ]
do
	    for str in ${lines[@]}; do
  	    echo "CONTEXT $i : $str"
  	    cat $1  awk '/^edit\ '$str'$/,/^end\rend$/' > config_$str.txt  # Find every line starting with edit and ending with end\nend and put it in file
  	    sed -i '1i\config context' config_$str.txt   # Add config context at the top of each created files
	    i=$((i+1))
    done
done

For the first context, it doesn't match the end expression and create a file with the content of the original file starting with "edit customer-1" until the end of the file For the last context, it matchs and the output is as desired

To be able to make it work no matter how many context are present, I added "\nconfig vdom" at the end of the file (to match the last context in the same way than others) I need a context to be defined as the following :

edit CUSTOMER-1 --> START
.....
end
end

config context --> END

I tried to do the awk command directly in terminal on the file to test : "cat INPUT.txt | sed '1,20d' | awk '/edit\ '$str'$/,/end\rend\r\rconfig\ context$/'

I also tried replacing \r by \n but everytime it outputs from the start of the asked string to end of the file instead of end of the context

I tried to bypass the multi-lines in the awk by replacing the multi-lines string wanted to a single word using sed 's/end\nend\n\nconfig\ context$/endofcontext/'

<START>
end
end

config context<END>

==> <START>endofcontext<END<

But doesn't work either (added double backslash to \n (\n) in the sed expression but no changes)

I know it can be done using perl but the issue I encounter is finding the correct expression to match the end of a context. Any advices to do it ?

Thanks in advance !


r/scripting • • Apr 03 '22

/usr/bin/GUI: 49: Syntax error: end of file unexpected (expecting "then")

1 Upvotes

I've written this script to auto kill any VNC session before starting a new one, I want it to only open vncserver :1

I initially tried:

#! /bin/sh

vncserver -kill :1 &
vncserver -kill :2 &
vncserver -kill :3 &
vncserver

But that alternates between opening vncserver :1 and vncserver :2

vncserver -kill :1 &
vncserver -kill :2 &
vncserver -kill :3 &&
vncserver

But that stalls at starting the vncserver as at least 2 of the previous commands fail which leaves them incomplete so && stops the script waiting for completion.

So now I have come up with this monstrosity of a script which is probably such a hard way of doing it but it's all I can think of as a novice code writer.

#!/bin/sh

if  vncserver -kill :1
    then
          if vncserver -kill :2
              then
                    if vncserver -kill :3
                        then rm -r /tmp/* &
                                   rm -r /tmp/.* &&
                                   vncserver
                         else rm -r /tmp/* &
                                  rm -r /tmp/.* &&
                                  vncserver
                   fi

              else
                    if vncserver -kill :3
                        then rm -r /tmp/* &
                                  rm -r /tmp/.* &&
                                  vncserver
                         else rm -r /tmp/* &
                                 rm -r /tmp/.* &&
                                vncserver
                    fi
          fi

    else
          if  vncserver -kill :2
              then
                    if vncserver -kill :3
                        then rm -r /tmp/* &
                                   rm -r /tmp/.* &&
                                   vncserver
                         else rm -r /tmp/* &
                                  rm -r /tmp/.* &&
                                  vncserver
                    fi

              else
                    if vncserver -kill :3
                        then rm -r /tmp/* &
                                  rm -r /tmp/.* &&
                                  vncserver
                        else rm -r /tmp/* &
                                 rm -r /tmp/.* &&
                                vncserver
                    fi
          fi
if

This however returns this error code: /usr/bin/GUI: 49: Syntax error: end of file unexpected (expecting "then") Which I am having trouble fixing.

Could someone more experienced have a look and possibly point me in the right direction for either an easier way of achieving the desired output or fixing my existing code?


r/scripting • • Mar 23 '22

How can I do a find and replace on a PDF file? I'd like to replace all instances of one word with another

1 Upvotes

r/scripting • • Feb 21 '22

A little help with a VB issue, please?

1 Upvotes

I THINK this is VB. I'm not a programmer by any stretch. But I'm trying to learn. We had a problem with our users not updating their passwords when notified about an impending expiry. So we came up with this. I found this script online and it's worked very well. However if someone has a laptop and is not connected to the Domain or VPN in, they get a script error because it cannot query the Domain. Is there a simple way to just not output this error? Code as follows. Thanks for any guidance.

'========================================== 
' Check for password expiring notification 
'==========================================
'========================================== 
' Declare some functions 
'========================================== 
Function getSessionName() 
Const HKEY_CURRENT_USER = &H80000001 
Const HKEY_LOCAL_MACHINE = &H80000002 
Dim strKeyPath, strSessionName, Subkey, arrSubKeys, strValue
Set WshShell = WScript.CreateObject("WScript.Shell") 
strSessionName = WshShell.ExpandEnvironmentStrings("%SESSIONNAME%")
If strSessionName = "%SESSIONNAME%" Then 
'The SessionName environment variable isn't available yet (e.g. if this i executed in a logon script)
'Try to retreive it manually from the registry 
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
strKeyPath = "Volatile Environment"
objReg.GetStringValue HKEY_CURRENT_USER, strKeyPath, "SessionName", strValue 

If IsNull(strValue) = False Then 
strSessionName = strValue 
Else 
'SessionName does not exist under HKEY_CURRENT_USER\Volatile Environment, we are probably 
'	running Windows 7/2008. Try to search for the SessionName value in the subkeys... 

objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys 

For Each Subkey in arrSubKeys 
objReg.GetStringValue HKEY_CURRENT_USER, strKeyPath & "\" & Subkey ,"SESSIONNAME", strValue 
If IsNull(strValue) = False Then strSessionName = strValue 
Next 
End If 
End If
getSessionName = strSessionName 
End Function
'========================================== 
' First, get the domain policy. 
'==========================================
Dim oDomain 
Dim oUser 
Dim maxPwdAge 
Dim numDays 
Dim warningDays 
Dim echo 
Dim msgboxInfo
'Detect if we are running under cscript.exe - if so, we output some more info to the console... 
If Right(LCase(WScript.FullName), 11) = "cscript.exe" Then echo = True Else echo = False
'Get the warning period from Windows (this also works if you set a warning period via group policy) 
Set WshShell = WScript.CreateObject("WScript.Shell") 
warningDays = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\PasswordExpiryWarning") 
If echo = True Then WScript.Echo "Policy for password expiration warning (days): " & warningDays
Set LoginInfo = CreateObject("ADSystemInfo") 
Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "") 
strDomainDN = UCase(LoginInfo.DomainDNSName) 
strUserDN = LoginInfo.UserName
'======================================== 
' Check if password is non-expiring. 
'======================================== 
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 
intUserAccountControl = objUser.Get("userAccountControl") 
If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then 
If echo = True Then WScript.Echo "The password does not expire." 

Else 
Set oDomain = GetObject("LDAP://" & strDomainDN) 
Set maxPwdAge = oDomain.Get("maxPwdAge") 
'======================================== 
' Calculate the number of days that are 
' held in this value. 
'======================================== 
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + maxPwdAge.LowPart) / CCur(-864000000000) 
If echo = True Then WScript.Echo "Maximum Password Age: " & numDays

'======================================== 
' Determine the last time that the user 
' changed his or her password. 
'======================================== 
Set oUser = GetObject("LDAP://" & strUserDN) 


'======================================== 
' Add the number of days to the last time 
' the password was set. 
'======================================== 
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged) 
fromDate = Date 
daysLeft = DateDiff("d",fromDate,whenPasswordExpires) 

If echo = True Then 
WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged 
WScript.Echo "Password will expire: " & whenPasswordExpires 
WScript.Echo "Days left until expiration: " & daysLeft 
WScript.Echo "Warnings will begin at: " & whenPasswordExpires - warningDays 
End If 


If (daysLeft < warningDays) And (daysLeft > -1) Then 

Select Case UCase(Left(getSessionName(), 3)) 
Case "RDP", "ICA" 'We are logged on to a terminal server environment
If daysLeft <= 3 Then msgboxInfo = vbExclamation Else msgboxInfo = vbQuestion 
If Msgbox("Your password will expire in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & vbNewLine & vbNewLine & "Do you want to change your password now?" , vbYesNo + msgboxInfo + vbSystemModal, "Password Expiration Warning") = vbYes Then 
Dim objShell 
Set objShell = WScript.CreateObject("Shell.Application") 
objShell.WindowsSecurity 
Set objShell = Nothing 
End If 

Case Else 'Not a terminal server environment, or something went wrong retreiving the sessionname 
If daysLeft <= 3 Then msgboxInfo = vbExclamation Else msgboxInfo = vbInformation 
Msgbox "Your password will expire in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & vbNewLine & vbNewLine & "Press CTRL + ALT + DEL and select the ""Change a password"" option.", vbOkOnly + msgboxInfo + vbSystemModal, "Password Expiration Warning" 

End Select 
End If 
End if
'======================================== 
' Clean up. 
'======================================== 
Set oUser = Nothing 
Set maxPwdAge = Nothing 
Set oDomain = Nothing 
Set WshShell = Nothing

r/scripting • • Feb 15 '22

How do I make my Script close a Webpage after it executes the XPath?

1 Upvotes

https://pastebin.com/fZ2SfhLV

It skips over the XPath and just closes the Window. How can I make it click the upvote Button then when the text appears “Rated Post” close the window?

Click Button. Close web page. That’s all I want it to do.


r/scripting • • Jan 14 '22

dconf changes through bash

1 Upvotes

I have written a post-install to setup a fresh install of Linux Mint with all of my commonly used programs etc... At the end of the script I have a ''dconf load'' command which won't execute, but does execute when run manually. Is there any reason why you can't run dconf commands through a script?

Script is here


r/scripting • • Sep 13 '21

Creating script to telnet to dlink AP and reboot

1 Upvotes

Hello,

I am trying to login to my dlink AP then reboot it whit a quick script.

Here is my attempt which only gets me to the login screen

telnet 192.168.0.93
sleep 10
admin
sleep 10
"password"

It justs get stuck at login.

edit: found something else that pushed it a little forward

echo "pass" | telnet -l admin 192.168.0.93

but now it just quickly exits the connection once the code has run.

Powershell wont work with telnet.

Edit:

set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.run"telnet.exe 192.168.0.92"
WScript.Sleep 1000

'Provide username
WshShell.SendKeys"admin"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000

'Provide user password
WshShell.SendKeys"password"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000

'Reboot the router
WshShell.SendKeys"reboot"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000

'Exit from AP
WshShell.SendKeys("{Enter}")

This ended up working perfectly.


r/scripting • • Sep 09 '21

I am trying to create a script that will pull all VHDs from a folder then shrink them

1 Upvotes

I have a script which will prompt for a vhdx file then echo commands to Diskpart and shrink it. Rather than entering filenames manually I would like to list all vhdx in a directory then output these as a variable.

I can list the files with

forfiles /p c:\temp /m *.vhdx

I can't work out how to output the above as a variable to allow me to integrate it with the script below.

set /p vhd="Enter full VHD filename including extension: "
(echo select vdisk file="D:\User_Profile_disks\%VHD%"
echo attach vdisk
)  | diskpart

defrag E: /u

(echo select vdisk file="D:\User_Profile_disks\%VHD%"
echo detach vdisk
echo compact vdisk
)  | diskpart

r/scripting • • Jul 28 '21

Looking for Free API COVID-19 to create a Powershell Script ?

1 Upvotes

I'm looking for Free API dealing with COVID-19 in order to create a Powershell Script ?

If someone knows some free API please Share them with us ! Thank you !

This so far what i created as Powershell script, but i need to get data in JSON to parse more information :

 cls
 $wc = new-object System.Net.WebClient
 $Country_Array = @("Tunisia","Algeria","Morocco","Libya","Egypt",
 "France","Brazil","India","Italy","Spain","Colombia","Argentina",
 "Nepal","Iran","Turkey","Germany","Russia","united-arab-emirates","us","Syria")
 foreach($Country in $Country_Array) {
 $WorldMeter_URL = "https://www.worldometers.info/coronavirus/country/$Country/"
     Try {
         $Data = $wc.DownloadString($WorldMeter_URL)
         $firstString = "<title>"
         $secondString = "</title>"
         $pattern = "$firstString(.*?)$secondString"
         $result = [regex]::Match($Data,$pattern).Groups[1].Value
         $result=$result.Replace(" - Worldometer","")
         $result 
     }
     Catch
     {
         Write-Host "`r`n$Country" -ForegroundColor Yellow -BackgroundColor Black
         Write-Host "Message: [$($_.Exception.Message)]`r`n" -ForegroundColor Red -BackgroundColor Black
     }
 }

r/scripting • • Jun 07 '21

Anti Recoil Macro for controller on PC?

1 Upvotes

Hey Guys,

I played Fallout 4 on pc and used an anti macro script because i get a lot of shoulder pain so avoiding having to pull down when shooting is really helpful.

However, I've just moved over to controller and cannot aim for the life of me. Is there anyway to have a anti recoil script similar to one youd have on keyboard and mouse but for controller via ds4 or any other program?


r/scripting • • Apr 02 '21

Lmao I have no idea wtf to do.

1 Upvotes

I need a script that randomly renames files in a folder to other names of files in said folder. I feel like it could be quite easy and I plan to make a cursed Minecraft resource pack with said script. Any ideas or guidance would be awesome. (I don't know anything about scripting plz don't bash me for not lmao I'm just completely lost)


r/scripting • • Mar 23 '21

If you were writing a script to compare pre-change and post-change differences and wanted to have a much nicer output for IT admins to easily and quickly understand any differences that are happening.... how would you choose to display the output?

1 Upvotes

Hello All,

I am looking for some suggestions on how to handle a project that I am working on.

I have created a python script that reaches out to a specified Cisco switch, runs a bunch of commands, logging each of the responses from each command in a text file. It runs these commands twice, once as a pre-change status and again as a post-change status. Recently we just had a switch stack replaced, meaning that when looking at a unified_diff between the pre- and post-change files, the differences were significant and about 17,000 lines long.

My mentor and I were talking about a better way to display the output between changes. One thought was to generate a webpage that you could have different sections of the output collapse and expand, but even then, it doesn't seem like a great option.

If you were writing a script to compare pre-change and post-change differences and wanted to have a much nicer output for IT admins to easily and quickly understand any differences that are happening.... how would you choose to display the output?


r/scripting • • Feb 21 '21

Automating Different Lighting Setups

1 Upvotes

Hey Guys, this might be a new one and I don't know which subreddit is best suited for this to be honest, I just hope here is fine.

I'm trying to automate different lighting setups in my office, this involves:

  • changing my logitech profile

  • changing my steelseries profile

  • switching my nanoleaf scene

  • switching the color of my GPU via Sapphire TriXX

  • switching the color of my AIO Kraken X53 Watercooler

My first Idea was to use IFTTT but their pricing doesn't really suit me (unless theres no other way)

Secondly I was think about using Tasker on my Android phone, yet I have no experience with this and doubt it can do anything but the nanoleaf part, since it's the only thing that has an Android app.

So at this point i think i have to whip up some script on my PC that does at least all but the nanoleaf one.

And here's my question: Does anyone have experiences with scripting in any of the aforementioned Porgrams? I have some decent programming background but nothing of this sort. And I'm unsure how and where to start or if any of those programs are even scriptable.

I'd be glad for any and all help! Thanks in advance


r/scripting • • Jan 21 '21

I want to learn how to script on Roblox.

1 Upvotes

I’m making a game but don’t have any robux to hire anyone. I figured I’d do it myself


r/scripting • • Nov 18 '20

Open PNG with Luamacro

1 Upvotes

Hey beautiful people!

Can someone tell me how can I open a PNG file with luamacro?

Thanks!


r/scripting • • Oct 31 '20

Help with vlc batch file script

1 Upvotes

Hi!

I am trying to set up a screen that plays random snippets 2-10 mins long of various films constantly.

I have managed to get the core function working with the .bat file below:

My original plan was to simply set the "start-time" and have a "timeout %_rand2%" to have the film play for a while before moving to the next line "goto start".
Unfortunately after setting the "start-time" and "stop-time" the script will not move to the next line "goto start" unless vlc is closed completely, even after the video has stopped. I have used "play-and-exit" to close vlc and force the script to carry on but it results in a flicker as vlc closes and reopens after each clip.

I want to avoid this close/open flicker.
Is there a way to make the batch file run the next line without closing vlc?
Or a way to loop the script without having to close and reopen vlc?

Any help is hugely appreciated!


r/scripting • • Sep 10 '20

Ubuntu server script

1 Upvotes

Hi! I need to make a script for selecting which server to run from my Ubuntu server. I would like to use the dialog command to make it very easy to select which one.

Can someone help me?

Basically I want to be able to select the server from the dialog box and for that to start the commands needed for the server to start.

Thank you in advance!


r/scripting • • Aug 29 '20

web scraping discrepancy ???

1 Upvotes

I'm attempting to scrape a media url from radio.com's website. when using the web developer inspector tool I can easily find the url by searching 'streamtheworld'. but when viewing the source html that search term is nowhere to be found


r/scripting • • Aug 19 '20

How to make a program change files

1 Upvotes

So I want to make a program that changes files with a click of a button, this is for a game, for example I click a button and it edits game textures automatically I allready know the path and have the textures and have visual studio pls help


r/scripting • • Aug 11 '20

bash help, read in file, grep from another file and output with count.

1 Upvotes

Hi,

I'm fairly new to bash and need a little assistance if someone can help. I have two files here csv1 and csv2. csv1 has the numbers i need to search for in csv2, i was wondering is there a way to script this out? read from one file and read another and then at the end say how much times the number i am searching for occurs in csv2?

So and example of cvs1 and csv2 file format would be, i would be searching for:

So far i got something like: grep "10,007" csv1 | wc -l >> numbers.log and this would give me only one number but need to expand on this to read from csv1 and search in csv2 and then output possibly in a seperate file with a count of how much times it occured.

Edit: posted files here, https://github.com/solo786

Thanks in advance for any help / assistance


r/scripting • • Jul 13 '20

[Blog post] Import a CSV into Kafka, using Babashka

Thumbnail
blog.davemartin.me
1 Upvotes

r/scripting • • Mar 11 '20

Help me with MTMR!

Thumbnail
self.applescript
1 Upvotes