Created
August 24, 2020 15:39
-
-
Save moritzschaefer/7aa4c5a446fa85d59b9ed5066ded2bef to your computer and use it in GitHub Desktop.
Revisions
-
Moritz created this gist
Aug 24, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ function resize() { if (app.documents.length > 0) { var docRef = app.activeDocument; if (docRef.artboards.length > 1) { alert('Need exactly one artboard'); quit; } // Found 1 artboard var current = docRef.artboards[0].artboardRect; current[2] = current[0] + 595.2756; current[3] = current[1] - 841.8898; docRef.artboards[0].artboardRect = current; } else { alert('Open a document before running this script', 'Error running FitArtboardToArt.jsx'); } } var sourceFolder = Folder("C:\\Users\\Moritz\\Syncbox\\svgs"); var destFolder = Folder("C:\\Users\\Moritz\\Syncbox\\ais"); // optional: destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted SVG files.', '~' ); function getNewName(sourceDoc) { var ext, docName, newName, saveInFile, docName; docName = sourceDoc.name; ext = '.ai'; // new extension newName = ""; for ( var i = 0 ; docName[i] != "." ; i++ ) { newName += docName[i]; } newName += ext; // full svg name of the file // Create a file object to save the svg saveInFile = new File( destFolder + "\\" + newName ); return saveInFile; } if ( sourceFolder != null ) { var files = new Array(); //What kind of file in the source folder are you seeking? var fileType = "*.svg"; // Get all files matching that file type files = sourceFolder.getFiles( fileType ); if ( files.length > 0 ) { for ( i = 0; i < files.length; i++ ) { //Open a file var sourceDoc = app.open(files[i]); resize(); app.activeDocument.saveAs(getNewName(sourceDoc)); app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); } } alert( 'Complete' ); } else { alert( 'No matching files found' ); }