Copy Text and Store as a variable?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Copy Text and Store as a variable?

Post by RNIB » Thu Jul 30, 2015 3:43 pm

Apologies if this is a really obvious thing.


This is my code at present:

Code: Select all

SetFocus>SADiE6 Radio Producer - Phrase Detect Test Delete Me.edl
Wait>1
//Ask what prefix to start with
Input>PrefixNum, What file number do you want to start with?:,1
Input>PageNum, What page number do you want to start with?:,1
Label>Start
Let>strResponse=
//Ask how many times to run
Input>NumTimes, How Many Clips Are You Renaming?:,100
Let>Loop=0
Repeat>Loop
Let>WW_TIMEOUT=30
//Switch to SADiE and rename 1st heading
Press ALTGR
Press Enter
Release ALTGR
Wait>0.5
Press Home
Press Right * 4
Wait>0.5
Press Shift
Press End
Release Shift
Press CTRL
Send>c
Release CTRL
Press Home
Wait>0.5
Press Shift
Press End
Release Shift
VBSTART
VBEND
//prefix it with zeros to 3 chars long
Let>PrefixNum=PrefixNum
VBEval>Right("000" & "%PrefixNum%",3),PrefixNum
Send>%PrefixNum%_
Press Ctrl
Send>v
Release Ctrl
Send>_Page_
//prefix it with zeros to 3 chars long
Let>PageNum=PageNum
VBEval>Right("000" & "%PageNum%",3),PageNum
Send>%PageNum%
Press Enter
Wait>0.5
Press Down
Let>PrefixNum=PrefixNum+1
Let>PageNum=PageNum+1
Let>Loop=Loop+1
Until>Loop=NumTimes
What this does is renames a list of files in an audio editor so that they change from:

001_Chapter_1
001_Chapter_1
001_Chapter_1
002_Chapter_2
002_Chapter_2
002_Chapter_2

To:

001_Chapter_1_Page_001
002_Chapter_1_Page_002
003_Chapter_1_Page_003
004_Chapter_2_Page_004
005_Chapter_2_Page_005
006_Chapter_2_Page_006

What I would like to do is amend the code so that if the chapter name has been used once it doesn't paste it into the next file. In other words the files would be named as:

001_Chapter_1_Page_001
002_Page_002
003_Page_003
004_Chapter_2_Page_004
005_Page_005
006_Page_006

Is there a way I can capture the text it copies as a variable and then compare it against the text it copies on the next loop, or is there a better way of achieving that? Incidentally the files won't always be named as chapters nor will they always only be chapters, they could be a wide range of different names.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Copy Text and Store as a variable?

Post by JRL » Thu Jul 30, 2015 4:10 pm

Try this. Note the comments where I added or deleted. Untested so there could be typos or other issues but hopefully you get the idea.

Code: Select all

SetFocus>SADiE6 Radio Producer - Phrase Detect Test Delete Me.edl
Wait>1
//Ask what prefix to start with
Input>PrefixNum, What file number do you want to start with?:,1
Input>PageNum, What page number do you want to start with?:,1

//Preset list
Let>vChapterNameList=crlf

Label>Start
Let>strResponse=
//Ask how many times to run
Input>NumTimes, How Many Clips Are You Renaming?:,100
Let>Loop=0
Repeat>Loop
Let>WW_TIMEOUT=30
//Switch to SADiE and rename 1st heading
Press ALTGR
Press Enter
Release ALTGR
Wait>0.5
Press Home
Press Right * 4
Wait>0.5
Press Shift
Press End
Release Shift
Press CTRL
Send>c
Release CTRL
Press Home
Wait>0.5
Press Shift
Press End
Release Shift

//Get name from clipboard
GetClipBoard>vChapterName

VBSTART
VBEND
//prefix it with zeros to 3 chars long
Let>PrefixNum=PrefixNum
VBEval>Right("000" & "%PrefixNum%",3),PrefixNum
Send>%PrefixNum%_

//Test if name is in list
Separate>vChapterNameList,%crlf%%vChapterName%%crlf%,vNameTest
If>vNameTest_Count>1
Else
//Send the name (already acquired from the clipboard)
Send>%vChapterName%_
//Add this name to the name list
Let>vChapterNameList=%vChapterName%%crlf%
EndIf
//removed the leading underscore
Send>Page_
//prefix it with zeros to 3 chars long
Let>PageNum=PageNum
VBEval>Right("000" & "%PageNum%",3),PageNum
Send>%PageNum%
Press Enter
Wait>0.5
Press Down
Let>PrefixNum=PrefixNum+1
Let>PageNum=PageNum+1
Let>Loop=Loop+1
Until>Loop=NumTimes

RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Copy Text and Store as a variable?

Post by RNIB » Fri Jul 31, 2015 9:30 am

Many thanks JRL, much appreciated. Unfortunately I'm not having much luck getting it to work. I've not come across the Separate command before and don't quite understand what it's doing.

//Test if name is in list
Separate>vChapterNameList,%crlf%%vChapterName%%crlf%,vNameTest
If>vNameTest_Count>1

As it stands the macro runs without errors but it doesn't skip the chapter heading if it's already been used

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Copy Text and Store as a variable?

Post by JRL » Fri Jul 31, 2015 1:38 pm

Oops. I made a mistake in the concatenation of the list variable "vChapterNameList". I think the following will work properly.
RNIB wrote:I've not come across the Separate command before and don't quite understand what it's doing.
To get help for any Macro Scheduler function:
While in the Macro Scheduler script editor, put the cursor on the line with the function then press the "F1" key.

Doing this for Separate> displays:
Separate help wrote: Separate>list,delimiter,returnvar

Separate takes a list, a delimiter and returns the elements of the list. The command returns a number of variables, one for each list element, each with the suffix "_n" where n is the index of the element in the list. The variable names are determined by the name given in returnvar. e.g. returnvar_1, returnvar_2, etc. Also returned is the number of elements in the list, in returnvar_count.
We are using Separate> to determine if the chapter heading has already been used by Separating the list of previously used header names (variable "vChapterNameList") by the name of the currently acquired header (variable "vChapterName"). Since Separate returns a count of the elements produced by the use of the function, if the count is greater than one, the chapter name was found in the list.

The problem was that I gave you a faulty script that did not properly build the list (variable "vChapterNameList").

Code: Select all

SetFocus>SADiE6 Radio Producer - Phrase Detect Test Delete Me.edl
Wait>1
//Ask what prefix to start with
Input>PrefixNum, What file number do you want to start with?:,1
Input>PageNum, What page number do you want to start with?:,1
//Preset list
Let>vChapterNameList=crlf

Label>Start
Let>strResponse=
//Ask how many times to run
Input>NumTimes, How Many Clips Are You Renaming?:,100
Let>Loop=0
Repeat>Loop
Let>WW_TIMEOUT=30
//Switch to SADiE and rename 1st heading
Press ALTGR
Press Enter
Release ALTGR
Wait>0.5
Press Home
Press Right * 4
Wait>0.5
Press Shift
Press End
Release Shift
Press CTRL
Send>c
Release CTRL
Press Home
Wait>0.5
Press Shift
Press End
Release Shift
//Get name from clipboard
GetClipBoard>vChapterName
VBSTART
VBEND
//prefix it with zeros to 3 chars long
Let>PrefixNum=PrefixNum
VBEval>Right("000" & "%PrefixNum%",3),PrefixNum
Send>%PrefixNum%_
//Test if name is in list
Separate>vChapterNameList,%crlf%%vChapterName%%crlf%,vNameTest
If>vNameTest_Count>1
Else
//Send the name (already acquired from the clipboard)
Send>%vChapterName%_
//Add this name to the name list
Let>vChapterNameList=%vChapterNameList%%vChapterName%%crlf%
EndIf
//removed the leading underscore
Send>Page_
//prefix it with zeros to 3 chars long
Let>PageNum=PageNum
VBEval>Right("000" & "%PageNum%",3),PageNum
Send>%PageNum%
Press Enter
Wait>0.5
Press Down
Let>PrefixNum=PrefixNum+1
Let>PageNum=PageNum+1
Let>Loop=Loop+1
Until>Loop=NumTimes

RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Copy Text and Store as a variable?

Post by RNIB » Fri Jul 31, 2015 3:17 pm

Ahh I see. Think I follow it all, I'm very much a beginner at all of this and have no programming or scripting skills at all.

Tried the new code and it works perfectly, thank you so much I really appreciate it a lot.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts