Thursday, September 21, 2017

#1 2017-09-12 05:26:01 pm

DarthAztek
Member
Registered: 2016-12-07
Posts: 16

Prepending folder name?

My current script uses the following as part of a larger workflow:

Applescript:

display dialog "ENTER JOB CODE:" default answer "JobCode"
set projCode to text returned of result
set projectFolder to choose folder with prompt "SELECT PROJECT FOLDER for " & projCode

The user inputs projCode in the following format: ABCDEXY123. It's used to rename files using the same code with suffixes.

Is it possible to get just the "XY123" part of that code to prepend projectFolder's name as the final step in the overall script without having to add another step to input just that part projCode? Any insights would be appreciated. Thanks!

Offline

 

#2 2017-09-12 05:49:44 pm

haolesurferdude
Member
Registered: 2010-02-19
Posts: 104

Re: Prepending folder name?

If all you want to do is get the last 5 characters of projCode, the following line will work if you insert it after the line that sets projCode.

Applescript:


set prePend to characters ((length of projCode) - 4) thru (length of projCode) of projCode as text

The following will also work.

Applescript:


set prePend to characters (-5) thru (-1) of projCode as text

Last edited by haolesurferdude (2017-09-12 05:53:22 pm)

Offline

 

#3 2017-09-12 07:21:01 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5125

Re: Prepending folder name?

haolesurferdude wrote:

If all you want to do is get the last 5 characters of projCode, the following line will work if you insert it after the line that sets projCode.

Applescript:


set prePend to characters ((length of projCode) - 4) thru (length of projCode) of projCode as text

The following will also work.

Applescript:


set prePend to characters (-5) thru (-1) of projCode as text



haolesurferdude, neither of those is a good idea. They're inefficient -- you're making lists and then concatenating them -- and they're error-prone because the result will depend on the value of text item delimiters when you run it. Better to use this:

Applescript:

set prePend to text -5 thru -1 of projCode

Last edited by Shane Stanley (2017-09-12 07:21:44 pm)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2017-09-12 08:17:54 pm

DarthAztek
Member
Registered: 2016-12-07
Posts: 16

Re: Prepending folder name?

Thanks for the tips! However I think I mangled the follow-through. I got a stack overflow error when I tried:

Applescript:

set name of projectFolder to prePend & " - " & projectFolder as string

Offline

 

#5 2017-09-12 08:32:54 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5125

Re: Prepending folder name?

Try:

Applescript:

set name of projectFolder to (prePend & " - " & (get name of projectFolder))


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2017-09-12 08:49:21 pm

DarthAztek
Member
Registered: 2016-12-07
Posts: 16

Re: Prepending folder name?

Thanks for the quick response! Unfortunately I got an error stating that it couldn't get the name of the alias for the folder (followed by the full path name).

Offline

 

#7 2017-09-13 02:02:10 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4382

Re: Prepending folder name?

Hi.

You have to tell either System Events or the Finder to get and set the folder's name:

Applescript:

display dialog "ENTER JOB CODE:" default answer "JobCode"
set projCode to text returned of result
set projectFolder to choose folder with prompt "SELECT PROJECT FOLDER for " & projCode

set prepend to text -5 thru -1 of projCode
tell application "System Events" to set name of projectFolder to (prepend & " - " & (get name of projectFolder))


NG

Offline

 

#8 2017-09-14 10:27:19 pm

DarthAztek
Member
Registered: 2016-12-07
Posts: 16

Re: Prepending folder name?

Bingo! Thanks so much for your help!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)