is it possible to add tiers automatically in praat - praat

Is there a way to add tiers to Praat scripts automatically from the terminal? I want to iterate over thousands of files and add a second tier with a specific name and would prefer not to this manually.

I needed a refresher on how to glob files in Praat, some code is from here:
http://praatscriptingtutorial.com/loopingThroughFiles
So update wd$ to the dir you want to loop inside of. It picks up all the *.TextGrid files, loops over them, adding an extra tier (in this case to bottom and named "blah"), then saves andremoves the TextGrid from your objects window. I'd recommend making a backup of your working directory before you run this, in case you don't like the exact behavior, or have it save as some new modified fileName$.
clearinfo
wd$ = "C:/Users/Nick/Desktop/praat/*.TextGrid"
downloadsList = Create Strings as file list: "downloadsList", wd$
selectObject: downloadsList
numFiles = Get number of strings
for fileNum from 1 to numFiles
fileName$ = Get string: fileNum
Read from file: fileName$
Insert interval tier: 2, "blah"
Save as text file: fileName$
Remove
selectObject: downloadsList
printline Added for textgrid 'numFiles' 'fileName$'
endfor
Remove

Related

Can Mac's Automator scan a folders contents & lists the files that are over a certain length?

I work in media production at a university, we work on Mac systems, but our servers are windows based.
Illegal characters & long file names are causing us problems when transferring our production files to the server.
To prevent file transfers failing & being sent to a holding pen in our DAM system i'm looking to create a simple Automator App that can be used by the production team to do the following;
Accept source folder as input for the app.
Scan contents & replace the following characters ()\/[]"*?<>|+ with an underscore.
Scan contents & for file names longer than 100 characters
Log / report on the affected files for our producers to amend.
Within Automator I have had success with replacing the illegal characters using a find & replace rule for each, but I'm not sure of the apple script that would be required to check the file name lengths & reporting all changes.
I'll be eternally grateful if anyone would be able to suggest a route forwards!
Obviously, I have no clue what you might be passing along, nor how you might be replacing the text in filenames, nor exactly what you would like to report, as you don't really provide any of those details. However, here is a straightforward way to test for filenames longer than a given length within automator.
To provide the initial file list to test, I begin with three actions:
Get Selected Finder Items
Get Folder Contents ('repeat for each subfolder found' is checked)
Filter Finder Items ('kind is document')
This will pass along a list of alias file objects to the fourth 'run applescript' action, as input.
on run {input, parameters}
set fList to input
set nList to {} -- becomes list of filenames
set cList to {} -- becomes list of filename lengths
tell application "Finder"
repeat with ff in fList -- list of file aliases
set nn to name of ff
set end of nList to nn
set end of cList to length of nn
end repeat
end tell
set longList to {}
repeat with cc from 1 to length of cList
if item cc of cList is greater than 100 then
set end of longList to item cc of nList -- names with more than 100 characters
end if
end repeat
return longList
end run
This should be run when a folder is selected in the Finder.
Essentially, what this does is take the input (i.e. list of file aliases) and create corresponding lists of filenames and filename lengths. The script then loops through the list of lengths looking for items > 100 and and returns a list of matching filenames. If instead, you set end of longListā€¦ to items from fList then it will return a list of file aliases.
If this isn't what you're looking for, please advise. The above works under Sierra.

How do I rename and move a file downloaded to 'Downloads" using Automator, with or without Applescript, Shell Script or Javascript?

I am a newbie to programming and therefore please excuse my lack of knowledge. I have trawled the site and the internet but have not found an answer to what seems like a simple problem.
I would like to automate the filing and renaming of some personal and business documents - they are bank statements so the numbers are anonymised. I am interested in understanding the code so I can adapt it after too, for further actions (and maybe for others to use).
The documents are downloaded into the (mac) downloads folder. Typically they have this name: "Statement--12345678--98765432--1-06-2020-30-06-2020.pdf" The two sets of numbers at the beginning are not these generic ones but there are 8 figures (though the first number sometimes is not listed as it is a "0"). The second set of two numbers refers to two dates, in day--month--year format. Sometimes the first date starts on the last day of the previous month!
As a newbie I started with Automator - using a Folder Action to move the individual files to a named folder (by year). I then wanted to rename them so that the second date comes first in the name in YYYYMMDD format, so that they will automatically be listed in date order in the year folder. The full name would become "YYYYMMDD 98765432 Month YY".
I can move the files and automatically (thanks to automator); I can even add the current date at the beginning of the name in the right format (but it will be the current date not the date in the file). But I cannot do what I really want: change the name based on the date in the filename.
I then looked at AppleScript. The answers below solve the naming problem - THANK YOU!
But when I try to pick up a bunch of files - there are 25 of them (happily found and moved by Automator (Find files and Move files) the output is not recognised as an input into AppleScript. I get "Can't get files XXXX as alias" or if I try to create a variable, that is not defined (though I have tried numerous times... as {}, as "", as item 1 of input).
I do apologise if this is not clear, but I am trying my best to explain it, and do not understand terms such as 'terminal ls'.
Any help, advice and commentary gratefully received. I really do want to try to understand the code so I can apply the learning! Thank you,
John
Okay, your problem is to extract multiple parts of the name.
The trick is to explode it into small parts. GREP is a good tool, but tricky with applescript "out of the box".
I use a subroutine called "textSplit" to do the job. Once every part of the filename is available in variables, you should be able to build any file or folder name...
Here's my way to solve this :
set thisFileName to "Document--12345678--98765432--1-06-2020-30-06-2020.pdf"
-- first we split the name using the "--" separator
set mainParts to textSplit(thisFileName, "--")
-- we now copy the result to variables to handle it
copy mainParts to {prefixOne, numberOne, numberTwo, theTwoDates}
--> prefixOne = "Document"
--> numberOne = "12345678"
--> numberTwo = "98765432"
--> theTwoDates = "1-06-2020-30-06-2020.pdf"
-- get rid of the extension
set theDatesWithoutExtension to first item of textSplit(theTwoDates, ".")
-- split the dates
set splitDates to textSplit(theDatesWithoutExtension, "-")
-- copy result into nice variables
copy splitDates to {dayOne, monthOne, yearOne, dayTwo, monthTwo, yearTwo}
-- and then build the filename with whatever you want
set myNewFileName to yearOne & monthOne & dayOne & space & numberTwo & space & monthTwo & "-" & yearTwo & ".pdf"
--> "2020061 98765432 06-2020.pdf"
-- make folders, move files, renameā€¦
-- ================================================================================================
on textSplit(theText, theDelimiter)
-- this will split a string and returns a list of substrings
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {theDelimiter}
set theList to every text item of theText
set AppleScript's text item delimiters to saveDelim
return (theList)
end textSplit

Looping over all databases in a directory

I need to loop over all databases in a certain directory, where the database name is ACPwxyz.mdb, where wxyz is the equivalent to an MMYY value for the period that database was used for.
E.g., the database for July 2017 would be ACP0717.mdb.
I've never written in VB6 before and I totally hate it, but it's an extension to an existing project so I'm stuck with it!
Is there a way of looping over all files in a directory, checking if the file name follows the format of ACPwxyz.mdb or not, and if it does, then opening a connection to it?
I've looked around a bit and see Dir(x, y), but I'm not sure if I can use this in this situation?
Any tips would be appreciated.
You can use Dir, yes.
If you use something like this:
Dim strFile As String
strFile = Dir(yourDBPath, "ACP????.mdb") ' mdb for MS-Access files
Do Until strFile = ""
If Len(strFile) = 11 Then ' Ensure the DB file name is 11 characters, which yours are
'Do something // You can also check the file name doesn't = a certain name if needed
End If
strFile = Dir
Loop
Dir accepts either an asterisk (*), or a question mark (?) as wildcards in file names, so this will look for any database in the set path that is called ACP followed by 4 characters.

VBS - Replace certain text entries in various files

I created a template for my test suite in QTP where the level of abstraction (parameterization) is sufficiently good.
I would now need to populate a new test suite from the existing pattern, thus replacing certain entries with other ones in various files.
For example one of the words I deliberately put in the script suite pattern is [Template], therefore I would need to copy and paste the template with a different name, change all the entries by [Template] to the new string and so forth.
Any code would be appreciated as my VBScript skills are not optimal ;)
Thanks in advance!
Use this demo script:
Option Explicit
Dim gMap : Set gMap = Createobject("Scripting.Dictionary")
Function replGMap(sM, nPos, sSrc)
replGMap = gMap(sM)
End Function
Dim reMap : Set reMap = New RegExp
reMap.Global = True
reMap.Pattern = "\[\w+\]"
gMap("[A]") = "abra"
gMap("[B]") = "cadabra"
WScript.Echo reMap.Replace("1[A]2[A]3[B]4[A]5", GetRef("replGMap"))
output:
abra2abra3cadabra4abra5
as a list of keywords to look up in the VBScript Docs. For using a function in .Replace, see here.
The FileSystemObject provides the means (Open/CreateTextFile, ReadAll, Write) to read and write files.

Use Automator and Applescript to move files to folders based on File Name

I have a folder which contains the following files:
Elephant.19864.archive.other.pdf
Elephant.17334.other.something.pdf
Turnip.19864.something.knight.pdf
Camera.22378.nothing.elf.pdf
I want these files moved to the following structure
Archive
Elephant
Elephant.19864.pdf
Elephant.17334.pdf
Turnip
Turnip.19864.pdf
Camera.HighRes
Camera.HighRes.22378.pdf
The generated files consist of a word or multiple words, followed by a sequence of number, followed by other words and then the extension. I want to move these into a folder named the word or words before the numbers, and remove all of the words between the numbers and the extension (.pdf in this case).
If the folder does not exist, then I have to create it.
I thought this would be quite simple using Automator or an AppleScript, but I don't seem to be able to get my head around it.
Is this easy using Automator/AppleScript if so, what should I be looking at
It's easy, it's just not obvious at first. Some things to get you started.
To parse the file names to get your folder names, you need to separate the name into a list...
set AppleScript's text item delimiters to {"."}
set fileNameComponents to (every text item in fileName) as list
set AppleScript's text item delimiters to oldDelims
--> returns: {"Elephant", "19864", "archive", "other", "pdf"}
The list has a 1-based index, so item 1 is "Elephant" and item 5 is "pdf". To mash the file name together, then all you need is this
set theFileName to (item 1 of fileNameComponents & item 2 of fileNameComponents & item 5 of fileNameComponents) as string
To create a folder, just use the following...
tell application "Finder"
set theNewFolder to make new folder at (theTargetFolder as alias) with properties {name:newFolderName, owner privileges:read write, group privileges:read write, everyones privileges:read write}
end tell
To move a file, all you need is this...
tell application "Finder"
set fileMoved to move theTargetFile to theTargetFolder
end tell
To rename a file, use something like the following...
set theFileToRename to theTargetFilePath as alias -- alias is important here
set name of theFileToRename to theFileName
I suggest first creating a list of all of the target files, then for each file in the list create the folders based on its name, move the file, finally renaming it once it is in its final location.
Add salt to taste.

Resources