Skip to content

Instantly share code, notes, and snippets.

View kuyseng's full-sized avatar

Kuyseng CHHOEUN kuyseng

  • Yoolk Inc.
  • Phnom Penh, Cambodia
View GitHub Profile
@kuyseng
kuyseng / gist:2792114
Created May 26, 2012 04:00
javascript: indesign combine text files into one
function combine_text_file ( files, path, new_name ) {
if( files.length>0 ) {
var all_string = "";
for (var i = 0, len = files.length; i < len; i++) {
all_string += read_text_file( files[i] );
};
return write_text_file( all_string, path, new_name ); // return file
};
};
@kuyseng
kuyseng / gist:2792119
Created May 26, 2012 04:01
javascript: indesign get date string
function get_date_string(para_date) {
var date = para_date || new Date();
var day = (date.getDate() > 10 ) ? date.getDate() : ("0" + date.getDate() ),
month = ((date.getMonth()+1) > 10 ) ? (date.getMonth()+1) : ("0" + (date.getMonth()+1) ),
year = (date.getFullYear() > 10 ) ? date.getFullYear() : ("0" + date.getFullYear() ),
hours = (date.getHours() > 10 ) ? date.getHours() : ("0" + date.getHours() ),
minutes = (date.getMinutes() > 10 ) ? date.getMinutes() : ("0" + date.getMinutes() );
return year + month + day + "_" + hours + minutes;
};
@kuyseng
kuyseng / gist:2792123
Created May 26, 2012 04:03
javascript: indesign show dialog to open next file
function show_dialog(message, opened_number) {
// update it v 0.1.1
var defaultScriptPreference = app.scriptPreferences.userInteractionLevel;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
var myDialog = app.dialogs.add({name:"Continue with another file or finish?",canCancel:true});
var all_messages = [];
with(myDialog){
with(dialogColumns.add()){
with(dialogRows.add()) {
@kuyseng
kuyseng / gist:2792275
Created May 26, 2012 04:52
javascript: photoshop save as file type
function save_as_file_type(fileObj) { // { fileName, fileType, path, quality }
if (app.documents.length == 0) {
alert("Please have an 'photoshop' document before running this script.");
return;
}
var quality = fileObj.quality || 3, //default 3
path = fileObj.path || app.activeDocument.path,
document = fileObj.document || app.activeDocument,
fileName = document.name,
fileType = fileObj.fileType,
@kuyseng
kuyseng / gist:2867476
Created June 4, 2012 09:38
javascript: photoshop save for web
function saveForWebPNG(outputFolderStr, filename)
{
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;
if (filename.length > 27) {
file = new File(outputFolderStr + "/temp.png");
activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);
@kuyseng
kuyseng / gist:2872224
Created June 5, 2012 02:46
javascript: photoshop save for web with metadata
function Cs4SFW(FileName,Quality,MetaData, Profile,Progressive) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
/*
reference -> http://forums.adobe.com/message/2582725
Metadata:-
'MDAl' All metadata 'MDNn' No metadata
'MDCp' Copywright 'MDCC' Copyright and contact
'MDAx' All except camera info
Profile:-
@kuyseng
kuyseng / gist:2958106
Created June 20, 2012 04:20
javascript: array shuffle
// reference: http://www.hardcode.nl/subcategory_1/article_317-array-shuffle-function
Array.prototype.shuffle = function() {
var len = this.length;
var i = len;
while (i--) {
var p = parseInt(Math.random()*len);
var t = this[i];
this[i] = this[p];
this[p] = t;
}
@kuyseng
kuyseng / gist:2958113
Created June 20, 2012 04:22
javascript: get array from range min max
function get_range (min, max) {
var arr = [];
for (var i = 0; i <= (max - min); i++) {
arr[i] = min + i;
};
return arr;
}
@kuyseng
kuyseng / fitiamge
Created June 25, 2012 08:48
javascript: photoshop fit Image width height
// reference: http://www.ps-scripts.com/bb/viewtopic.php?f=10&t=3409&sid=f4a754d74f5b92fa6732a283c0e20fd9
function FitImage( inWidth, inHeight ) {
var desc = new ActionDescriptor();
var unitPixels = charIDToTypeID( '#Pxl' );
desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );
executeAction( runtimeEventID, desc, DialogModes.NO );
};
@kuyseng
kuyseng / gist:2994150
Created June 26, 2012 07:37
javascript: photoshop save for web call menu
function RunSaveForWeb() {
var id637 = charIDToTypeID( "slct" );
var desc89 = new ActionDescriptor();
var id638 = charIDToTypeID( "null" );
var ref21 = new ActionReference();
var id639 = charIDToTypeID( "Mn " );
var id640 = charIDToTypeID( "MnIt" );
var id641 = charIDToTypeID( "Svfw" );
ref21.putEnumerated( id639, id640, id641 );
desc89.putReference( id638, ref21 );