StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
soooulp  
#1 Posted : Wednesday, December 15, 2021 10:52:40 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 4/23/2020(UTC)
Posts: 105
China

Thanks: 37 times
Was thanked: 6 time(s) in 5 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:
if(action.Control.HWnd.ToInt32() == sp.DesktopWindowListView().HWnd.ToInt32()) {
            //do something
}else{
          //do something
}



Rob  
#2 Posted : Wednesday, December 15, 2021 3:03:45 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,109
United States
Location: Tampa, FL

Thanks: 24 times
Was thanked: 336 time(s) in 293 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

thanks 1 user thanked Rob for this useful post.
soooulp on 12/15/2021(UTC)
soooulp  
#3 Posted : Wednesday, December 15, 2021 3:25:11 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 4/23/2020(UTC)
Posts: 105
China

Thanks: 37 times
Was thanked: 6 time(s) in 5 post(s)
Originally Posted by: Rob Go to Quoted Post
Try this setup for hotkey:


Works perfect. I can use the DisplayText to show the success information.

Thank you soooo much, Rob.


Users browsing this topic
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.