StrokesPlus.net Forum
»
General Discussion
»
General Discussion
»
Need help for transfer the AHK unzip script to S+net
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
The following Ahk code will use the 7-Zip program to unzip the file to the current fold or a new fold with the same file name by the shortcut. There are two problems with transferring it to S+net, first, how to use the SplitPath function on S+net after getting the selected zip file path on Desktop or on Explorer? Second, I find the second code will recognize the current window from the Desktop to the Explorer with an action, but how to use it on the Hotkey? AHK Code
Code:^+y::
temp = %clipboard%
;KeyWait, LButton, D
;send {LButton}
sleep,100
Send, {Ctrl Down}c{Ctrl Up}
sleep,200
file = %clipboard% ;get file address
clipboard = %temp% ;restore clipboard
outdir := getdir(file)
runwait, "C:\Program Files\7-Zip\7z.exe" x "%file%" -o"%outdir%" -y,,hide ;Unzip to the same fold and add a new fold
TrayTip, ,7zip has finished extracting "%file%", 1, 16
return
getdir(input)
{
SplitPath, input,,parentdir,,filenoext
final = %parentdir%\%filenoext%
return final
}
Code:if(action.Control.HWnd.ToInt32() == sp.DesktopWindowListView().HWnd.ToInt32()) {
//do something
}else{
//do something
}
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Try this setup for hotkey: Code:var wndHandle = sp.ForegroundWindow().HWnd;
var desktopHandle = sp.DesktopWindowListView().HWnd;
var result;
var fullPath = "";
var outdir = "";
var selectedFiles;
var isDesktop = false;
var success = false;
if(wndHandle.ToInt32() == desktopHandle.ToInt32() || sp.LastFocusControl().HWnd.ToInt32() == desktopHandle.ToInt32()) {
//Desktop
selectedFiles = sp.GetSelectedFilesOnDesktop();
isDesktop = true;
} else {
//Not Desktop
selectedFiles = sp.GetSelectedFilesInExplorer(wndHandle);
}
//Only do this when a single file is selected
if(selectedFiles.Length == 1) {
fullPath = selectedFiles[0];
if(isDesktop) {
fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + fullPath;
}
var fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fullPath);
var folderName = System.IO.Path.GetDirectoryName(fullPath);
outdir = folderName + "\\" + fileNameNoExt;
result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe',
`x "${fullPath}" -o"${outdir}" -y`,
'open', 'hidden', false, true, true);
if(result == 0) {
success = true;
sp.ShowBalloonTip("ZIP Extract", `7zip has finished extracting\n${fullPath}\nTo:\n${outdir}`, "info", 1000);
}
}
if(!success) {
sp.ShowBalloonTip("ZIP Extract", `Unexpected error:\nExit Code: ${result}\nfullPath: ${fullPath}\noutdir: ${outdir}\nselectedFiles.Length: ${selectedFiles.Length}\nisDesktop: ${isDesktop}`, "error", 1000);
}
Edited by user Wednesday, December 15, 2021 3:09:51 PM(UTC)
| Reason: Not specified
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Originally Posted by: Rob Try this setup for hotkey:
Code:var wndHandle = sp.ForegroundWindow().HWnd;
var desktopHandle = sp.DesktopWindowListView().HWnd;
var result;
var fullPath = "";
var outdir = "";
var selectedFiles;
var isDesktop = false;
var success = false;
if(wndHandle.ToInt32() == desktopHandle.ToInt32() || sp.LastFocusControl().HWnd.ToInt32() == desktopHandle.ToInt32()) {
//Desktop
selectedFiles = sp.GetSelectedFilesOnDesktop();
isDesktop = true;
} else {
//Not Desktop
selectedFiles = sp.GetSelectedFilesInExplorer(wndHandle);
}
//Only do this when a single file is selected
if(selectedFiles.Length == 1) {
fullPath = selectedFiles[0];
if(isDesktop) {
fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + fullPath;
}
var fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fullPath);
var folderName = System.IO.Path.GetDirectoryName(fullPath);
outdir = folderName + "\\" + fileNameNoExt;
result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe',
`x "${fullPath}" -o"${outdir}" -y`,
'open', 'hidden', false, true, true);
if(result == 0) {
success = true;
sp.ShowBalloonTip("ZIP Extract", `7zip has finished extracting\n${fullPath}\nTo:\n${outdir}`, "info", 1000);
}
}
if(!success) {
sp.ShowBalloonTip("ZIP Extract", `Unexpected error:\nExit Code: ${result}\nfullPath: ${fullPath}\noutdir: ${outdir}\nselectedFiles.Length: ${selectedFiles.Length}\nisDesktop: ${isDesktop}`, "error", 1000);
}
Works perfect. I can use the DisplayText to show the success information. Thank you soooo much, Rob.
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
General Discussion
»
Need help for transfer the AHK unzip script to S+net
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close