function main() { //-- called with an argument: //-- 'import' => copy from sharedclipboardfile onto system clipboard //-- 'export' => copy from system clipboard into sharedclipboardfile var i; //-- general counter var r = 1; //-- general results holder var sharedclipboardfile = "\My Documents\multiclip.txt"; var clpmgrbinary = "\\Program Files\\ClipMgr\\ClipMgr.Exe"; var sleeptime = 0; var debug = 0; var dateformats[]; var timeformats[]; var clips[]; var currentclip; var maxclips = 99; var idx = 0; //-- holds current idx when building clips[] //-- y, yy, yyyy = year //-- M, MM = month //-- d, dd = day of month //dateformats[] = {"yyyy-MM-dd", "dd-MM-yy", "dd-MM-yyyy", "d-M-yy", "d-M-yyyy", "yyyy/MM/dd", "dd/MM/yy", "dd/MM/yyyy", "d/M/yy", "d/M/yyyy"}; dateformats[] = {"yyyy-MM-dd", "yyyy/MM/dd", "dd-MM-yyyy", "dd/MM/yyyy"}; //-- H, HH = 24 hour clock //-- h, hh = 12 hour clock //-- m, mm = minute //-- s, ss = second timeformats = {"HH:mm:ss"}; createdirectory("clips"); //-- read existing clips from file readclips(clips, maxclips); if (arg[0] == "import") { getsharedclip(sharedclipboardfile); currentclip = clipget(); clipcount = gethashcount(clips); if (debug == 1) { puts("Clipcount is %clipcount%\n"); } if ((clipcount == 0) || ((clipcount >= 1) && (clips[0] != currentclip))) { //-- no clips yet OR //-- the first clip is different to currentclip //-- so we will save currentclip to _clip* writeclips(clips, maxclips, clipcount, currentclip); } sleep(sleeptime); exit; } if (arg[0] == "export") { currentclip = clipget(); setsharedclip(sharedclipboardfile, currentclip); clipcount = gethashcount(clips); if (debug == 1) { puts("Clipcount is %clipcount%\n"); } if ((clipcount == 0) || ((clipcount >= 1) && (clips[0] != currentclip))) { //-- no clips yet OR //-- the first clip is different to currentclip //-- so we will save currentclip to _clip* writeclips(clips, maxclips, clipcount, currentclip); } sleep(sleeptime); exit; } idx = gethashcount(clips); //-- add the date/time formats for (i = 0; i < gethashcount(dateformats); i++) { //puts(getdate("%dateformats[i]%\n")); clips[idx++] = getdate("%dateformats[i]%"); } for (i = 0; i < gethashcount(dateformats); i++) { //puts(gettime("%timeformats[i]%\n")); if (i < 2) { clips[idx++] = getdate("%dateformats[i]%") + " " + gettime("%timeformats[0]%"); } else { clips[idx++] = gettime("%timeformats[0]%") + " " + getdate("%dateformats[i]%"); } } while (r >= 0) { r = getcbdialog("Clips", clips, "Copy", "Exit", "Export", "ClipMgr"); //Button code is 0 //Button code is 1000 => 3rd button //Button code is 10000 => 4th button //Copy if (r >= 0 && r < 1000) { clipset(clips[r]); } //Export if (r >= 1000 && r < 10000) { setsharedclip(sharedclipboardfile, clips[r - 1000]); } //ClipMgr if (r >= 10000) { shell(clpmgrbinary); } } sleep(sleeptime); } function readclips(&clips, maxclips) { //-- read in existing clip files (_clip-01.txt _clip-02.txt ...) var buf; var i, idx, fp; idx = 0; for (i = 0; i < maxclips; i++) { filename = "clips/_clip-"; if (len(i) < 2) { filename = filename + "0"; } filename = filename + i + ".txt"; //puts("Filename is [%filename%]\n"); fp = fileopen("read", filename); if (fp != -1) { fileread(fp, buf); if (debug == 1) { puts("[%filename%] contents::\n%buf%\n"); } clips[idx++] = buf; } else { //puts("The file '%filename%' could not be opened for reading\n"); } fileclose(fp); } return; } function writeclips(&clips, maxclips, &clipcount, currentclip) { var i, fp; //clipcount = gethashcount(clips); //puts("Inside writeclips(), clipcount is %clipcount%\n"); if (clipcount == 0) { //puts("No clips yet, use currentclip\n"); clips[0] = currentclip; } else { //puts("Reordering clips\n"); for (i = clipcount; i > 0; i--) { if (i < maxclips) { clips[i] = clips[i-1]; } } clips[0] = currentclip; } clipcount = gethashcount(clips); for (i = 0; i < maxclips; i++) { filename = "clips/_clip-"; if (len(i) < 2) { filename = filename + "0"; } filename = filename + i + ".txt"; //puts("Filename is [%filename%]\n"); //puts("clip contents [%clips[i]%]\n"); if (i < clipcount) { fp = fileopen("new", filename); if (fp != -1) { r = filewrite(fp, clips[i], len(clips[i])); if (r == -1) { puts("Error writing to '%filename%'\n"); } else { if (debug == 1) { puts("Wrote file '%filename%'\n"); } } } else { puts("The file '%filename%' could not be opened for writing\n"); } } else { //-- remove the duplicate clips (these are the clips "left behind" when you //-- manually remove clips and the above ordering process closes up the holes) deletefile(filename); } } } function getsharedclip(sharedclipboardfile) { var fp; var buf = ""; var charsread = 0; fp = fileopen("read", sharedclipboardfile); if (fp == -1) { fileclose(fp); msgbox("*** error opening file %sharedclipboardfile% for reading ***\n", "Fatal error!", 0); return; } else { charsread = fileread(fp, &buf); fileclose(fp); puts("Read %charsread% characters from %sharedclipboardfile%\n"); //buf = translate(buf, "\n", "\r"); clipset(buf); return buf; } } function setsharedclip(sharedclipboardfile, buf) { var fp; fp = fileopen("new", sharedclipboardfile); if (fp == -1) { fileclose(fp); msgbox("*** error opening file %sharedclipboardfile% for writing ***\n", "Fatal error!", 0); return; } else { status = filewrite(fp, buf, len(buf)); fileclose(fp); puts("Clipboard contents written to file %sharedclipboardfile%\n"); } }