-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathQuickSave.ini
More file actions
100 lines (81 loc) · 2.47 KB
/
Copy pathQuickSave.ini
File metadata and controls
100 lines (81 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
[Command]
Name=QuickSave
Command="
copyq:
// To save a clipboard item as file to a preset path using tags as it's file name.
// Avoid a dialogue for user input
// Initial user setup:
currentPath('C:/abc/xyz')
// Set your default path here for once:
var words = 3
// number of words to use from tags (not number of tags)
var defaultname = 'clip'
// default file name if there are no tags.
var suffices = {
'image/svg': 'svg',
'image/png': 'png',
'image/jpeg': 'jpg',
'image/jpg': 'jpg',
'image/bmp': 'bmp',
'text/html': 'html',
'text/plain' : 'txt',
}
function addSuffix(fileName, format)
{
var suffix = suffices[format]
return suffix ? fileName + \".\" + suffix : fileName
}
function filterFormats(format)
{
return /^[a-z]/.test(format) && !/^application\\/x/.test(format)
}
function itemFormats(row)
{
return str(read('?', row))
.split('\\n')
.filter(filterFormats)
}
function formatPriority(format)
{
var k = Object.keys(suffices);
var i = k.indexOf(format);
return i === -1 ? k.length : i
}
function reorderFormats(formats)
{
formats.sort(function(lhs, rhs){
var i = formatPriority(lhs);
var j = formatPriority(rhs);
return i === j ? lhs.localeCompare(rhs) : i - j;
})
}
if (selectedtab()) tab(selectedtab())
var row = selectedtab() ? currentitem() : -1
var formats = itemFormats(row)
reorderFormats(formats)
var tags = str(data('application/x-copyq-tags'))
var nametag = tags.trim().replace(/[^a-z0-9]+/gi, '_').split('_',words).join('_')
// simplify & only take first two words from tags. can be modified.
var defaultFileName = currentPath()+'/'+(tags=='' ? defaultname : nametag)
// that's without ext
var id = index()+1
// just to start from 1.
var format = formats[0]
// name incrementally to avoid overwriting.
do {
var filename = defaultFileName +'-'+ id
var filenameExt = addSuffix(filename, format)
var f = File(filenameExt)
id++
}
while (f.exists())
if (!f.open()) {
popup('Failed to open \"' + f.fileName() + '\"', f.errorString())
abort()
}
f.write(selectedtab() ? getitem(currentitem())[format] : clipboard(format))
f.close()
popup(\"Item Saved\", 'Item saved as \"' + f.fileName() + '\".')"
InMenu=true
Icon=\xf56d
Shortcut=ctrl+alt+s