Custom Script Converter: What can you do with it?

Is there any way to extract the file name from a file path, and add ", " (that’s comma,space) to it? I’m using this to track a list of picture-names that someone has selected using the Concatenate IA, and write it to one cell in Excel.

Currently I have a work around that is working (thanks to @Seb as always), but I’m hoping for something a little cleaner.

An example is this:
INPUT: D:\IntuiFace\MedMtgImages-PhotoSelector\Files\InterfaceAssets\FileSystemBrowsingJS\Images\18ADA_00001.jpg

DESIRED OUTPUT: 18ADA_00001.jpg,

It’s possible the number of characters in the file name could vary depending on the file. I was hoping there’d be a way to extract it by a delimiter, but there isn’t currently a selection for that type of slash “\”.

Thanks for any ideas!

Hi @AlexB,

I couldn’t resist to answer you tonight on this one, since you’ll see as easy it can be, when you know how to write a little JavaScript :slight_smile:

Here’s the code for your converter:

INPUT.substring(INPUT.lastIndexOf("\\")+1)

It basically finds the last index of the \ character in the INPUT string (still need to escape this special character, thus the \ in the code) and returns what’s after this index, +1 not to have the \ in the returned string.

Give it a try and confirm me it does what you were looking for :wink:

3 Likes

You’re awesome! I’ll give it a try and report back. Is there a way to build in a comma and a space after the last character too? That way it’ll look like a nice list when it gets written to the excel cell.
Would I just add ", " to it?

INPUT.substring(INPUT.lastIndexOf("\\")+1) + ", "

:wink:

2 Likes

@Alex, @Seb
Thanks to you both, it works GREAT!

Follow up question for future use of this expression: If I wanted to get the X-th index, instead of the last index…what would that look like?

Use this:

folders = INPUT.split("\\");
folders[folders.length-2];

Quick explanation: the split command will break down the line into an array of elements, using “\” as separator.
folder[X] will display the Xth element of this array and I use folders.length-2 to target the 2nd before the end in this array.

Enjoy :wink:

1 Like

Very cool Alex, thanks for sharing this! Going to save this in my converter tools doc.

1 Like

By the way, I think @Seb and @Alex should host a Javascript Masterclass for everyone.

1 Like

I’ll pass on that, I only have a small knowledge about “vanilla” Javascript, I’d prefer to host cooking lessons :wink:

1 Like

In that case, please call it, “Cooking with Camacho”

3 Likes

One thing i have thought of over the weekend.

Is it possible to have an animated/faded gradient rectangle with a 3 tone colour?

Could this be done with Javascript?

Like the CSS alternative https://www.gradient-animator.com/

GO… @Alex @Seb?

2 Likes

Oo! Yes! I’d like to play around with that in future projects! :slight_smile:

By the way, I think @Seb and @Alex should host a Javascript Masterclass for everyone.

Yes please! I know nothing about Javascript, but I would love to learn.

1 Like

Animating a gradient isn’t something that can be done today, as far as I know, since you currently can’t bind the gradient properties to anything.

@megan and @AlexB you could start by having a look at tutorials here: JavaScript Tutorial :wink:

1 Like

Thanks, @Seb!

That’s a cool effect, @Promultis. I’d love to use that in IF someday. Thanks for sharing.

@Seb, I actually bought a beginners course some time ago, (on Udemy) but IF is keeping me too busy to go through the course! Haha, maybe that’s a good thing?

2 Likes

Here goes a new example of the Custom Script: Tips: how to fast forward a video by 10 seconds

1 Like

Adding another converter trick, this time it will help you calculate the number of days between a given date and current day.

In this example, I have dates stored in Excel, formatted as string like this dd/MM/YYYY

image

Then, I’m using this converter on a binding to this date

var date1 = new Date(INPUT);
var date2 = new Date();
var difference = date1.getTime() - date2.getTime();
var days = Math.ceil(difference / (1000 * 3600 * 24));
if (days>0) {
     "Today, it's \n" + days + " days until " + INPUT
} else  {
     "Today, it's \n" + days*(-1) + " days since " + INPUT
}

Final result in Experience

Please note that, according to your locale date format, you may need to tweak your initial date value.
For more, please check Date object javascript documentation.

Cheers.

3 Likes

Linking back another Custom Script Converter usage, converting an HH:mm:ss.sss formatted duration to total seconds

1 Like