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

[JS] About Files

New Here ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

My name is avi. I have some difficulties in my script.
My problem is i want to create a file and i want to read and write that file.
For creating a file i am using following code but it is not working. Can anyone please look at it.

var myFile = new File("~/Desktop/amit.rtf");
myFile.create();

Currently i am working on two scripts. I want to create and write a text file using first program and then i need to read that text file using second program. Can anyone please tell me how to create, read and write a file using javascript(InDesign).

I just want to write a number in that file which i can read using second program. Please help me.

Thank you,
TOPICS
Scripting

Views

5.5K

Translate

Translate

Report

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
Participant ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Here's a script I use to create/read from/write to/delete a file:
//DESCRIPTION: Resets active window size or uses front window to set default size.


// Check for WindowDefault.txt; if present use it to set front window
// if not, use front window to set it after checking with user.

myPath = app.activeScript;
myParts = myPath.toString().split("/");
myParts[(myParts.length - 1)] = "WindowDefault" + app.version.slice(0,1) + ".txt";
myNewPath = myParts.join("/");

mySettingsFile = File(myNewPath);

// Before proceeding, check that there is a front window
// If not, offer user the chance to delete the current settings
if (app.windows.length < 1) {
beep();
if (confirm("No window is open; would you like to delete the settings file?")) {
// User said yes; check that it exists
if(mySettingsFile.exists) {
mySettingsFile.remove();
}
}
} else {

if (mySettingsFile.open("r")) {

savedBounds = mySettingsFile.read();
mySettingsFile.close();

myBounds = savedBounds.split(",");
for (i = 0; i<myBounds.length; i++) {
myBounds = Number(myBounds);
}
app.windows[0].bounds = myBounds;
} else {
beep();
if (confirm("Settings file is missing. Use current front window to set default?")) {
// User said: go to it.
new File(mySettingsFile);
mySettingsFile.open("w");
mySettingsFile.write(app.windows[0].bounds);
mySettingsFile.close();
}
}
}
Dave

Votes

Translate

Translate

Report

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
Participant ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Hmm, I'd use a different approach to the first bit these days:
myPath = app.activeScript;

mySettingsFile = File((myPath.parent) + "/WindowDefault" + app.version.slice(0,1) + ".txt");
Dave

Votes

Translate

Translate

Report

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
New Here ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Hi Avi,

Perhaps you don't need to read and write to a file.
You could also use scriptArgs.
Use app.scriptArgs.set("myNumber", myNumber) in the first script and
app.scriptArgs,get("myNumber") to get the number in your second script.

Grtn, Kees

Votes

Translate

Translate

Report

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
New Here ,
Jun 05, 2008 Jun 05, 2008

Copy link to clipboard

Copied

Hello KvD

Thank you KvD.
This is what i want. This is much easier way to do the thing what i am doing.
Can you tell me where the this ScriptArgs store the value. It will store the value in system buffer or some other place.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Hello, Unfortunately, I am not understanding this at all. I don't know scripts. From the previous posts a while ago (which unfortunately don't work any more). I need to do some steps to rename/copy/paste the script so that my work area stays that size instead of going the whole width of the desktop and behind the palettes. But unfortunately, I don't understand what is being said here in these postings re. scripts. 

Is there someway to get a script, change it's ending and then just put it somewhere in InDesign in CS4 and it will work. I understand that I also have to do another step of making sure something is not active any more (unchecking some box).

Thank you again for all your help.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

My windows scripts don't work in Windows ;-( because in Windows you can't turn off the Application Frame and with that on, the script can't change the positioning of the windows.

So, before we go any further, can you confirm that you are a Mac user?

Dave

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Yes, Mac. OS 10.5.x (I have to double check at home which OS). Thank you.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

In that case, here again is the script I use:

//DESCRIPTION: Resets active window size or uses front window to set default size.

// Check for WindowDefault.txt; if present use it to set front window
// if not, use front window to set it after checking with user.

myPath = app.activeScript;
myParts = myPath.toString().split("/");
myParts[(myParts.length - 1)] =  "WindowDefault" + app.version.slice(0,1) + ".txt";
myNewPath = myParts.join("/");

mySettingsFile = File(myNewPath);

// Before proceeding, check that there is a front window
// If not, offer user the chance to delete the current settings
if (app.windows.length < 1) {
beep();
if (confirm("No window is open; would you like to delete the settings file?")) {
  // User said yes; check that it exists
  if(mySettingsFile.exists) {
   mySettingsFile.remove();
  }
}
} else {

if (mySettingsFile.open("r")) {

  savedBounds = mySettingsFile.read();
  mySettingsFile.close();

  myBounds = savedBounds.split(",");
  for (i = 0; i<myBounds.length; i++) {
   myBounds = Number(myBounds);
  }
  app.windows[0].bounds = myBounds;
} else {
  beep();
  if (confirm("Settings file is missing. Use current front window to set default?")) {
   // User said: go to it.
   new File(mySettingsFile);
   mySettingsFile.open("w");
   mySettingsFile.write(app.windows[0].bounds);
   mySettingsFile.close();
  }
}
}

Instructions:

1. Copy and paste the script into a new ExtendScript Toolkit document.

  • To find ExtendScript Toolkit, look in Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS4/
  • Fire it up and it will present you with an empty document

2. Save the script to the Desktop (temporarily) with the name "Reset Window Position.jsx".

3. Fire up InDesign CS4.

4. Open the Scripts panel.

  • If it is not active, use Window/Automation to activate it

5. Right-click the folder named User and choose Reveal in Finder.

6. Create a folder inside that folder named "Windows"

7. Drag the script into that folder.

8. Use Edit/Keyboard Shortcuts and assign the shortcut Ctrl-W to this script (or any shortcut of your choice).

9. Make sure that Application Frame is not active (also on the Window menu).

10. Open a document and get its window the way you want it.

11. Run the script for the first time. It will ask if you want to use the front window to set your preference. Say yes.

That's it. Now, you can resize your front window by using the shortcut at any time. To change the preferences, you can open the text file it creates in that same Windows folder and twiddle with the numbers. Or, you can run the script with no document open to delete the preferences (it asks you first) and then repeat steps 10 and 11.

Dave

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Thank you. I will try it tonight.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Hi. I made a folder called Windows and then didn't know if I was

supposed to drag that inside the scripts folder so I did.


Then I tried to find the Edit/Keyboard Shortcuts which I couldn't find.


I tried to open a document but it opened to the whole desktop again.


What am I doing wrong.


Application Frame is not active.


6. Create a folder inside that folder named "Windows"

7. Drag the script into that folder.
8. Use Edit/Keyboard Shortcuts and assign the shortcut Ctrl-W to this script (or any shortcut of your choice).
9. Make sure that Application Fr
ame is not active (also on the Window menu).
10. Open a document and get its window the way you want it.
11. Run the script for the first time. It will ask if you want to use the front window to set your preference. Say yes.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Hi again.


I found edit/shortcuts and went to windows.


Reset Window Position does not show up


??

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Hi again. Also I opened windows twice and opened scripting and opened etc... till I got to Windows Reset Position.

I clicked on it and it resent the window... saved... reopened... window back to entire desktop width.

Thanks for help.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Yes, the Windows folder should be inside the Scripts Panel folder.

When you go to Edit/Keyboard Shortcuts you need to look for the Scripts section and then give the script a shortcut. If you have all the pre-installed scripts still in your Scripts panel you'll have to scroll down a long way to find it.

The script does nothing until you run it. The use of a shortcut is optional but if you don't have one it takes just as long to find the script in the panel as it does to fix the window manually.

Dave

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

OK I found scripts for keyboard shortcuts, I found reset window position.jsx.

Under new shortcut I put in Control/W

I clicked on OK

I got cannot modify the default set.

Create a new set based on the default set?

Now what? Thanks.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Take a deep breath.

Open a document.

Manually adjust the window to the size you want to be your default.

Run the script.

The script will ask you if you want the new size to be your default. Say yes (or OK or whatever the choice is).

Now, whenever you run the script it will make the front InDesign window that size.

Dave

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Maybe I am asking the wrong ?


How do I run the script? Should I be doing something diff?? Thanks again.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Hi again. I found runs script but the make it default never came up. It just

makes the window bigger or to size. I must be doing something wrong.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Well, I think I messed things up. I had the scripting window open and

there was the reset window one and a default one. I deleted the default one and now

the scripting doesn't work at all... the window stays the entire size of the desktop.

Is there a way to undo the damage? Why can't CS4 just fix the problem? Thanks again.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

There is nothing the script can do to change the size that InDesign uses to open a window.

What the script does is put you one keystroke away from getting the window to be the size you want it.

That's what it does. That's all that it does.

You just have to set up the defaults (as you did) and then run the script each time you create a new window.

Once you save a document and reopen it, it will open at the new size, but new windows will be at whatever size InDesign decides to make them.

Dave

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Why won't it open at the new size when you save and reopen the doc? Why does it keep

opening the full size of desktop every time? Thanks again.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

PS. I never got the window where it said, make the new size the default.

When I click on run script it just brings the window back and forth every

time? Thanks.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

I give up. Is there some inexpesive way to buy CS3. I went from

CS2 to CS4?

Votes

Translate

Translate

Report

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
Engaged ,
Apr 13, 2009 Apr 13, 2009

Copy link to clipboard

Copied

Hi again. I let it create a new set based on the default set.


I opened the window and did control/w and it resized the window.


I saved and closed and reopened, the window was back to being the entire width of desktop.

Votes

Translate

Translate

Report

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
New Here ,
May 22, 2009 May 22, 2009

Copy link to clipboard

Copied

I share Ann's frustration a little, though I was able to get the script going with the detailed instructs -- many thanks to Dave, this was bugging me to no end each time I opened something, at least now I can resize with a keystroke.

Why doesn't Adobe just let us set our own default screen-opening size in the Preferences?

Votes

Translate

Translate

Report

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