Skip to main content
dublove
Legend
Jun 13, 2025 4:27 AM UTC
Answered

How do I find out if the script file name contains the 'olo' character?

I want to find out if the current script name contains the olo character?
If it does, the script is executed.
If it does not contain olo, prompt: Do not change the script name.

Thank you very much.

m1b
m1bCorrect answer
Community Expert
Jun 13, 2025 5:35 AM UTC

@dublove you are right! This is because the .name property of File returns a string with non-ascii characters encoded, eg. test-亚洲区.js looks like: test-%E4%BA%9A%E6%B4%B2%E5%8C%BA.js

 
We can fix by using decodeURI(file.name).
var findWhat = '亚洲区';

// Get the current script file
var scriptFile = File($.fileName);

var fileName = decodeURI(scriptFile.name);

if (fileName.indexOf(findWhat) !== -1) {
    alert("The file name contains '" + findWhat + "'.");
} else {
    alert("The file name does NOT contain '" + findWhat + "'.");
}

4 replies

m1b
Community Expert
Community Expert
Jun 13, 2025 4:45 AM UTC

Perhaps I am not understanding your question, but does this help...

// Get the current script file
var scriptFile = File($.fileName);

// Get just the name (e.g., "myScript.jsx")
var fileName = scriptFile.name;

// Check if the name contains "olo"
if (fileName.indexOf("olo") !== -1) {
    alert("The file name contains 'olo'.");
} else {
    alert("The file name does NOT contain 'olo'.");
}

 

If this is what you mean, then in English we would say "... if the current script name contains the olo string" because character means only one character, but "string" can mean more than one characters. This is why the javascript primitive String has its name.

- Mark

Translate
dublove
dubloveAuthor
Legend
Jun 13, 2025 5:00 AM UTC

Hi m1b. Thank you.

Yes, just looking for strings.

It's not hard to be a clubber. I also looked around and tried to find it with a regular ......


Seems like this code only supports English?
Change "olo" to Chinese, e.g. "亚洲区"
and it won't be recognized.

Translate
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Jun 13, 2025 5:35 AM UTC

@dublove you are right! This is because the .name property of File returns a string with non-ascii characters encoded, eg. test-亚洲区.js looks like: test-%E4%BA%9A%E6%B4%B2%E5%8C%BA.js

 
We can fix by using decodeURI(file.name).
var findWhat = '亚洲区';

// Get the current script file
var scriptFile = File($.fileName);

var fileName = decodeURI(scriptFile.name);

if (fileName.indexOf(findWhat) !== -1) {
    alert("The file name contains '" + findWhat + "'.");
} else {
    alert("The file name does NOT contain '" + findWhat + "'.");
}
Translate