Skip to main content
dublove
Legend
June 13, 2025
Answered

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

  • June 13, 2025
  • 1 reply
  • 233 views

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.

Correct answer m1b

@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 + "'.");
}

1 reply

m1b
Community Expert
Community Expert
June 13, 2025

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

dublove
dubloveAuthor
Legend
June 13, 2025

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.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 13, 2025

@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 + "'.");
}