Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Issue with rename folder call by scriptMenuActions on Windows

Enthusiast ,
Mar 18, 2015 Mar 18, 2015

Hi,

The script renameFolder.jsx works fine from ESTK and  double-clic from Script panel (MacOS- Windows 7 - InDesign CC 2014)

//renameFolder.jsx

var myFile=File.openDialog("Choose the file","*.indd",false);

app.open(myFile);

var docFolder = Folder(app.activeDocument.filePath); 

app.activeDocument.close();

var mResult= docFolder.rename(docFolder.name + "_OK" );

alert(mResult);

But when I call this script from my custom menu myMenu.jsx the function rename() doesn't works on Windows 7 - InDesign CC 2014 (works fine on MacOS - InDesign CC 2014)


//myMenu.jsx

#targetengine 'session'

var myScriptFolder = Folder(app.activeScript.path);

myFolder = myScriptFolder.parent + '/Scripts Panel/';

//

var mMenu = app.menus.item("$ID/Main").submenus.item("myMenu");

if( mMenu != null) {mMenu.remove()};

var mMenu = app.menus.item("$ID/Main").submenus.add("myMenu");

// Title of menuItems

var sma1Title = "Rename folder ...";

// Create the Script Menu Action (SMA)

var sma1 = app.scriptMenuActions.item(sma1Title);

    if( sma1 == null ) {sma1 = app.scriptMenuActions.add(sma1Title);}

//

var mMenuItem1 = mMenu.menuItems.add(sma1);

// Add an Event Listener

sma1.addEventListener("onInvoke", RenameFolder, false);

sma1.addEventListener("beforeDisplay", disableMenu, false);

function RenameFolder(myEvent){

    app.doScript(File(myFolder + 'renameFolder.jsx'), ScriptLanguage.JAVASCRIPT);

}

function disableMenu(myEvent){

    if(app.documents.length > 0){

        sma1.enabled = true;

    }

    else{sma1.enabled = true;}

}

Thanks for your help ...

Regards

Ronald

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 18, 2015 Mar 18, 2015

What error are you receiving? "Doesn't work" is kind of a vague description.

My guess, after the .close() call indesign is still working a bit in the background to remove the .idlk file.

adding a $.sleep(100) after line 6 might fix it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 18, 2015 Mar 18, 2015

I agree for "Doesn't work" 😉

docFolder.rename(docFolder.name + "_OK" ) return false

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 19, 2015 Mar 19, 2015

Hi Ronald

Rename permissions can be quite tricky with Windows, you would probably be better forcing  the rename using a vbs doScipt.

Google how to do it.

Trevor

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 19, 2015 Mar 19, 2015

Hi,

Would be interested in getting more infos on this. I have a script of mine having troubles to rename folders on Windows 7/8 (Permission denied). I have looked since then for a VB to rename the folder as a superuser but couldn't find any yet.

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 19, 2015 Mar 19, 2015

@Trevor : I think  is not a rename permissions problem, my script works fine on Windows 7 from script panel, but not from my custom menu.

@Loic : I will explore also the VB to rename the folder. I'll let you know.

@Vamitul : No success with $.sleep()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 19, 2015 Mar 19, 2015

Try placing the script file in the application script folder rather than

the user script folder. It will often have higher permissions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 19, 2015 Mar 19, 2015

@Ariel : The script is already in the application script folder

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 19, 2015 Mar 19, 2015

I shall have a look into the vbs method on Sunday if I have time, regarding higher using a permission folder to place the script in you could try putting it in the Adobe scripts folder in my documents (if it doesn't exist then create it) this folder will get a high trusted status but I don't know if it's higher than the applications folder and also have doubt that even if it does that it would help but it's easy enough to give a go.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 20, 2015 Mar 20, 2015

@Trevor: same issue with the script in the Adobe scripts folder in my documents

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 22, 2015 Mar 22, 2015

Hi Ronald & Loic

the following does work

Tried and Tested after a lot of other attempts!

First Create a .bat file on the fly in the format of

Move ""C:\Users\Trevor\Documents\Presentations\test"" ""C:\Users\Trevor\Documents\Presentations\test_OK""

Then do the following doscript to run it minimized

myVBS = '''Dim objShell

Set objShell = CreateObject("WScript.Shell")

objShell.Run "C:\\rename.bat", 2'''

var mResult = app.doScript (myVBS ,ScriptLanguage.VISUAL_BASIC);

Change line 3 as needed.

Of course I am assuming you have summarized your script and it reality you are doing some processing of the ID file otherwise you would never try getting the folder by opening the id file!

You would just use parent and not have any problem in the first place.

Trevor

P.s. Loic let me know if that sorts out your problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 22, 2015 Mar 22, 2015

Here's the non-DIY version

Change the debug true to false in line 9 when done.

From experimenting it looks like trying to access the files can cause an access denial so use the debug to see what causes that.

I added a the line chcp 65001 for Unicode support which might be quite useful for the 4 or whatever billion people out there whose first Language is not the English (Americanese).  It might be bit buggy but looks likeit works well to me.

HTH Trevor

@Ariel Did you move down under or are you just standing on your head?

// By Trevor www.creative-scripts.com Coming Soon (Making progress) https://forums.adobe.com/message/7317040#7317040

// FOR WINDOWS ONLY IF YOU TRY RUNNING IT ON YOU MAC YOU CAN GET STUFFED

var myFile=File.openDialog("Choose the file","*.indd",false);

app.open(myFile);

var docFolder = Folder(app.activeDocument.filePath);

// DO SOME STUFF HERE!!!

app.activeDocument.close();

var docFolderOS = docFolder.fsName;

forceRename (docFolderOS, docFolderOS + "_OK", true); // true for debug false for normal use

function forceRename (oldPath, newPath, debug) {

    var tempBat = new File(Folder.temp + "/rename" + +new Date + ".bat");

    tempBat.encoding = "UTF-8";

    tempBat.lineFeed = "Windows";

    tempBat.open('w');

    tempBat.writeln("chcp 65001"); // DOS UTF-8 character map for Unicode

    tempBat.writeln('Move ""'+ oldPath + '"" ""' + newPath + '""'); // Can add dos flags after like -h or -a for hidden files etc.

    if (debug) tempBat.writeln('Pause'); // if it didn't do the job find out why rather than guessing :-!

    tempBat.close();

    var myVBS = '''Dim objShell

Set objShell = CreateObject("WScript.Shell")

objShell.Run "''' + tempBat.fsName + '"'

if (!debug) myVBS += ', 2'; // to minimize the command prompt window

app.doScript (myVBS ,ScriptLanguage.VISUAL_BASIC);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 22, 2015 Mar 22, 2015

Of course I am assuming you have summarized your script and it reality you are doing some processing of the ID file otherwise you would never try getting the folder by opening the id file!

You would just use parent and not have any problem in the first place.

Indeed it is a very summarized version

I test your script tomorrow, I don't have a PC at home ...


Thanks

Ronald



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 23, 2015 Mar 23, 2015

@Trevor: Beginning of the week very busy, I have not been able to test your script, I'll let you know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 23, 2015 Mar 23, 2015

@Trevor,

Same here sorry. I will come back to you asap, probably in two to three weeks from now.

Thanks for your efforts by advance,

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 29, 2015 Mar 29, 2015

Hi Trevor,

Unfortunately I have the same issue with your function function forceRename. Doesn't works on Windows 7 when I run from my custom menu myMenu.jsx.

What might be the difference between a script run from script panel and a script run from a custom menu ?


Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 01, 2015 Apr 01, 2015
LATEST

Hi

It works for me on Windows 7 from your custom menu.

I won't have time to look into thing for the next week+ and will try look into it after that.

Try just using execute() on the temp .bat file instead of using the vbs doscript, see what message it comes up when run in the debug mode.

Strip the code to their bare minimum with regards to file access including checks to see if the file exits before and after the rename attempt, if that works you can see whats triggering the look and try a work around,  for example instead of myFile.exits you could try myNewFile =  new File ("foo...."); myNewFile.exits

Keep us updated

Trevor

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines