-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path$$.Clipboard.jsxlib
More file actions
91 lines (73 loc) · 2.56 KB
/
Copy path$$.Clipboard.jsxlib
File metadata and controls
91 lines (73 loc) · 2.56 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
/*******************************************************************************
Name: Clipboard
Desc: Allows to get/set clipboard text.
Path: /etc/$$.Clipboard.jsxlib
Require: ---
Encoding: ÛȚF8
Core: NO
Kind: Module.
API: =get() set()
DOM-access: YES -- app.doScript(...) -- but supported in modal dialogs.
Todo: More tests
Created: 250209 (YYMMDD)
Modified: 250214 (YYMMDD)
*******************************************************************************/
;$$.hasOwnProperty('Clipboard') || eval(__(MODULE, $$, 'Clipboard', 250214, 'get'))
[PRIVATE]
({
OSLG: +ScriptLanguage[$$.inWin ? 'VISUAL_BASIC' : 'APPLESCRIPT_LANGUAGE'],
GETC: $$.inWin
//----------------------------------
// Clipboard getter thru app.doScript.
// => str [OK] | '' [EMPTY-OR-KO]
? function( sc)
{
sc = 'returnValue=CreateObject("htmlfile").ParentWindow.ClipboardData.Getdata("text")';
return String( app.doScript(sc,this.OSLG) || '' );
}
: function( sc)
{
sc = 'return (the clipboard as text)';
return String( app.doScript(sc,this.OSLG) || '' );
},
SETC: $$.inWin
//----------------------------------
// Clipboard setter (str only) thru app.doScript.
// => 1 [OK] | 0 [KO]
? function(/*str*/s, $$,ff,sc,err)
{
$$ = $.global[callee.µ.__root__]; // agnostic reference
if( !(ff=$$.File.temp(s,'txt',0, 'UTF16')) ) return 0; // IMPORTANT: Windows clipboard expects UTF16.
sc = 'returnValue=CreateObject("WScript.Shell").Run("cmd.exe /c type ""' + ff.fsName + '"" | clip",0,True)';
err = app.doScript(sc, this.OSLG);
$$.File.temp(); // Remove temp.
return err ? 0 : 1;
}
: function(/*str*/s, t,sc)
{
0 <= s.indexOf(t=String.DQ) && (s=s.split(t).join('\\"')); // Escape Double quotes -> `\\"`
// [REM250214] Going through the Finder would lead to security alert.
//sc = 'tell application "Finder"\rset the clipboard to "' + s + '"\rend tell';
sc = 'set the clipboard to "' + s + '"';
app.doScript(sc, this.OSLG);
return 1;
},
})
[PUBLIC]
({
get: function get_S( I)
//----------------------------------
// Get the clipboard text.
// => str [OK] | '' [EMPTY-OR-KO]
{
return callee.µ['~'].GETC();
},
set: function set_S_B(/*str*/txt, I,sc,r)
//----------------------------------
// Set the clipboard text.
// => 1 [OK] | 0 [KO]
{
'string' != typeof txt && (txt=String(txt||''));
return callee.µ['~'].SETC(txt);
},
})