Last active
March 24, 2017 14:34
-
-
Save hluk/be4481e6c72ab607c074 to your computer and use it in GitHub Desktop.
CopyQ - Save Texts on Disk
This file contains 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 characters
[Command] | |
Name=Save Texts from Tab | |
Command=" | |
copyq: | |
function encodeFileName(name) | |
{ | |
return name.replace(/\\s/g, '_').replace(/\\W/g, '') | |
} | |
function addFileNamePart(fileName, item, mime) | |
{ | |
var text = str(item[mime] || \"\").substring(0, 20) | |
if (text) | |
return fileName + (fileName ? \"_\" : \"\") + encodeFileName(text) | |
return fileName | |
} | |
var savePathKey = 'SaveTextsPath' | |
var savePath = | |
settings(savePathKey) || (Dir().homePath() + '/copyq_items/') | |
savePath = dialog( | |
'.title', 'Save Texts to Folder', | |
'.width', 320, | |
'Folder to Save Texts', File(savePath) | |
) | |
if (!savePath) | |
abort() | |
settings(savePathKey, savePath) | |
var mime = 'text/plain' | |
var tabName = selectedtab() | |
var date = new Date() | |
var path = | |
savePath + '/' + encodeFileName(tabName) + '_' + | |
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() | |
tab(tabName) | |
Dir(path).mkpath('.') | |
var count = 0; | |
for (var i = 0; i < size(); ++i) { | |
var item = getitem(i) | |
var text = item[mime] | |
if (!text) | |
continue | |
var fileName = \"\" | |
// window title | |
fileName = addFileNamePart(fileName, item, 'application/x-copyq-owner-window-title') | |
// copied time | |
fileName = addFileNamePart(fileName, item, 'application/x-copyq-time') | |
// row number | |
fileName += (fileName ? \"_\" : \"\") + i | |
fileName = path + '/' + fileName + '.txt' | |
var f = File(fileName) | |
if (!f.open()) { | |
popup('Failed to open \"' + f.fileName() + '\"', f.errorString()) | |
abort() | |
} | |
f.write(text) | |
++count | |
} | |
popup( | |
'Tab saved (' + count + ' items)', | |
'Items saved in \"' + path + '\"' | |
)" | |
InMenu=true | |
Icon=\xf0c7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved to copyq-commands repository.