how to modify current keyboard shirtcuts or load a custom .kys file?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

tyrtyrtyr
Posts: 2
Joined: Tue Mar 13, 2018 1:00 pm

how to modify current keyboard shirtcuts or load a custom .kys file?

Post by tyrtyrtyr »

Hi everyone,

does anyone know how can I load my keyboard shortcuts file or modify the current one with script? So that new shortcuts would work without reloading Photoshop. I've tried to force open a .kys file with app.system, but nothing happens

Code: Select all


var kysFile = new File("/C/Users/Sergey Kritskiy/Desktop/temp/test/brng (modified) Copy Copy Copy.kys"),
psFile = new File(app.path + "/Photoshop.exe");

app.system('"' +psFile.fsName + '" "' + kysFile.fsName + '"');
//output from this was "C:\Program Files\Adobe\Adobe Photoshop CC 2018\Photoshop.exe" "C:\Users\Sergey Kritskiy\Desktop\temp\test\brng (modified) Copy Copy Copy.kys"
Thanks!
Sergey
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: how to modify current keyboard shirtcuts or load a custom .kys file?

Post by Kukurykus »

Both profiles and shortcuts you can edit manually with ExtendScript ToolKit as XML files. Profiles don't have extension, while shortcuts got .kys. Moreover shortcuts may be part of profile file if you set in Photoshop some Profile and check Shortcuts box. They can be found for ex. at end of:

C:\Users\User\AppData\Roaming\Adobe\Adobe Photoshop CS6\Adobe Photoshop CS6 Settings

- Shortcuts (directly at end of above path)

- Profiles (when you add \WorkSpaces)

Code: Select all

function rw(v1, v2, v3) {v2.open(v1), v1 < 'w' ? v3 = v2.read() : v2.write(v3), v2.close(); return v3}

rd = rw('r', log = File('~/Desktop/Profile'))
rd = rd.replace(/(e=")(.*)(?=">\n.*>F2)/, 'some script')
rw('w', File('~/Desktop/Profile'), rd)
I didn't test above code to answer all your questions but it searches for script that is set to F2 key and change its name to 'some script' in Profile file I copied earlier to desktop. I don't remember well but I think once when I tried it, it was like it. Later I'll take a look...
tyrtyrtyr
Posts: 2
Joined: Tue Mar 13, 2018 1:00 pm

Re: how to modify current keyboard shirtcuts or load a custom .kys file?

Post by tyrtyrtyr »

Thanks Kukurykus,

Just rewriting the kys file requires Photoshop restart for new keys to be recognized, my goal was to do so without PS reloading :/
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: how to modify current keyboard shirtcuts or load a custom .kys file?

Post by Kukurykus »

You don't need to relaunch Photoshop. There is a way to create / replace a shortcut:

Let's say you already have Photoshop Workspace ('Window / Workspace') named 'Profile'.
That workspace during creation was bound to your Keyboard Shortcuts, and now is chosen.

You want to make 'F2' shortcut to 'Alert' script that currently doesn't have any shortcut.
Later you even want to change previously chosen shortcut to the same 'Alert' script for 'F3'

'Profile' workspace, 'Alert' script and 'F2', 'F3' shortcuts can be changed for your needs...

Code: Select all

function rw(v1, v2, v3) {v2.open(v1), v1 < 'w' ? v3 = v2.read() : v2.write(v3), v2.close(); return v3}

function sTT(v) {return stringIDToTypeID(v)} function wrk(v1, v2, v3, v4, v5) {
eval("(ref1" + (nA = " = new Action") + (R = "Reference") + "()).put" +
(v1 == 'make' ? "Class" : "Name") + "(sTT(" + (w = "'workspace'") + "), v2)")
for(i = 0; i < (arr = [R + "(sTT('null'), ref", "String(sTT('name'), v"]).length; i++) {
eval("(dsc" + (I = i + 1) + nA + "Descriptor()).put" + arr[i] + I + ")")
}
for(i = 0; i < (arr = ['palette', 'keyboard' + (C = 'Customization'), 'menu' + C, 'replace']).length; i++) {
eval("dsc2.putBoolean(sTT(arr[i]), " + (i ? "true" : "v" + (i + 3)) + ")")
}
dsc1.putObject(sTT('using'), sTT(w), dsc2), executeAction(sTT(v1), dsc1, DialogModes.NO)
// v1: 'make', 'select', 'reset', 'delete'; v2: workspace name; v3: boolean, v4: boolean, v5: boolean
}

ver = version.slice(0, 2) > 13 ? '.psw' : ''

pth = File(Folder.userData + '/Adobe/' + (fld = Folder.startup.displayName.match
(/.*?(?=( \(|$))/)[0]) + '/' + fld + ' Settings/WorkSpaces/Profile' + ver)

rd = rw('r', pth); if (!/Script_Alert/.test(rd)) {
rd = rd.replace(/(modified="(?:0|1)">\n)\t(<command)/,
'$1\t<command kind="dynamic" name="Script_Alert">' +
'\r\t\t<shortcut>F2</shortcut>\r\t</command>\r\t$2')
rw('w', pth, rd)
}
else rw('w', pth, rd.replace(/(_Alert">\n\t\t<shortcut>)F2</, '$1F3<'))

wrk('reset', 'Profile', false, false, false)
Attachments
Shortcut to Script.rar
(1.05 KiB) Downloaded 444 times