Hello:
I've written a script to format the Horoscope for our newspaper. But when I run it, the place feature opens the last folder InDesign used, as it normally does. But I want it to open a specific directory. I've tried several versions of place, but none seem to work.
(The script deletes the text we don't need, formats the other text, and saves the finished text box as a snippet in a directory. We use TownNews for pagination, so we can auto import the snippet when needed.)
I did get the script to work if I use the Folder feature, but it places the new text file over the current text file on the document. Of course, I can make the script delete the current text box and then place.
But I would like to have the script "place..." and open a specifiic directory.
I've tried everything I know of to get the "Place..." to open a specific directory, but no luck.
Here is a copy of the script.
I would appreciate any feedback/help anyone can offfer.
Thanks.
Larry
var allPgs = app.activeDocument.pages;
for(var pCnt = 0; pCnt < allPgs.length; pCnt++)
var pg = allPgs[pCnt];
var masItms = pg.masterPageItems;
app.menuActions.itemByName('Place...').invoke();
app.findTextPreferences = app.changeTextPreferences = null;
main();
function main() {
if (app.layoutWindows.length == 0) return;
if (app.selection.length != 1 || !app.selection[0].hasOwnProperty('changeGrep')) {
alert('Please select only one textframe or text range!');
return;
}
var changeObject = app.selection[0].parentStory;
if (changeObject.hasOwnProperty('characters') && changeObject.characters.length == 0) return;
var doc = app.documents[0];
var style;
var options = app.findChangeGrepOptions.properties;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[8Horoscope_Find_From_Beginning_To_ARIES]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"(\\A.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r(?=ARIES))|(\\A.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r(?=ARIES))"});
app.changeGrepPreferences.properties = ({});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[6Horoscope_Find_Delete_Bottom]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"(\\rFOR\\sTODAY\\’S\\sBIRTHDAY.+\\r.+\\r.+\\r.+\\r.+)|(\\rFOR\\sTODAY\\’S\\sBIRTHDAY.+\\r.+\\r.+\\r.+\\r.+\\r.+)|(\\rFOR\\sTODAY\\’S\\sBIRTHDAY.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+)|(\\rFOR\\sTODAY\\’S\\sBIRTHDAY.+\\r.+\\r.+\\r.+\\r.+\\r.+\\r.+)"});
app.changeGrepPreferences.properties = ({});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[7Horoscope_Find_Change_Signs_To_Bold]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"ARIES\\r.+\\r|TAURUS\\r.+\\r|GEMINI\\r.+\\r|CANCER\\r.+\\r|LEO\\r.+\\r|VIRGO\\r.+\\r|LIBRA\\r.+|SCORPIO\\r.+\\r|SAGITTARIUS\\r.+\\r|(?#)CAPRICORN\\r.+\\r|AQUARIUS\\r.+\\r|PISCES\\r.+\\r"});
app.changeGrepPreferences.properties = ({appliedFont:"News Gothic T", fontStyle:"Bold"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[9Horoscope_Delete_Return_At_Bottom]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"\\Z\\r"});
app.changeGrepPreferences.properties = ({});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findChangeGrepOptions.properties = options;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[Horoscope_NEW_Delate_Text_After_Pisces_0422]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"\\rFOR TODAY’S BIRTHDAY\\r.+\\rBirthdate of:.+\\r.+\\r.+"});
app.changeGrepPreferences.properties = ({});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findChangeGrepOptions.properties = options;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
};
function getStyleByString(docOrGroup, string, property) {
if (string == '[No character style]') return docOrGroup[property][0];
if (string == '[No paragraph style]') return docOrGroup[property][0];
if (string == 'NormalParagraphStyle') return docOrGroup[property][1];
stringResult = string.match (/^(.*?[^\\]):(.*)$/);
var styleName = (stringResult) ? stringResult[1] : string;
styleName = styleName.replace (/\\:/g, ':');
remainingString = (stringResult) ? stringResult[2] : '';
var newProperty = (stringResult) ? property.replace(/s$/, '') + 'Groups' : property;
var styleOrGroup = docOrGroup[newProperty].itemByName(styleName);
if (remainingString.length > 0 && styleOrGroup.isValid) styleOrGroup = getStyleByString (styleOrGroup, remainingString, property);
return styleOrGroup;
};
var dir = Folder("/\\10.10.1.15/tcms/tcms_purged/mdjonline_com/autoflow\\/");
var myFile = dir.saveDlg('This is always the same folder?','',false);
//var myFile = File.saveDialog();
// if (!myFile) return;
if (!myFile.toString().match(/\.idms$/)) myFile = File(myFile + ".idms");
if (app.selection.length > 1){
var myObj = app.activeWindow.activePage.groups.add(app.selection);
myObj.exportFile(ExportFormat.INDESIGN_SNIPPET, myFile, false);
myObj.ungroup();
}
else{
app.selection[0].exportFile(ExportFormat.INDESIGN_SNIPPET, myFile, false);
}