Skip to content

Enhancement: new builtin shortcuts: active_office_file #2936

Open
@1208nn

Description

@1208nn

Just like {active_explorer_path}

It's not difficult.

This function might help users use plugins to do something on what they are focusing quickly or users can drag it in the flow search result to share it quickly.

I think it would be better if we add a copy button in the builtin shortcuts list.

An example in python:

import os
import time
import win32gui
import win32api
import win32com.client
import win32process
import win32con


def get_active_window():
    window = win32gui.GetForegroundWindow()
    thread_process_id = win32process.GetWindowThreadProcessId(window)
    return thread_process_id[1]


def get_file_path():
    pid = get_active_window()
    handle = win32api.OpenProcess(
        win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False, pid)
    exe_path = win32process.GetModuleFileNameEx(handle, 0)
    if "winword.exe" in exe_path.lower():
        return os.path.abspath(win32com.client.Dispatch("Word.Application").ActiveDocument.FullName)
    elif "powerpnt.exe" in exe_path.lower():
        return os.path.abspath(win32com.client.Dispatch("PowerPoint.Application").ActivePresentation.FullName)
    elif "excel.exe" in exe_path.lower():
        return os.path.abspath(win32com.client.Dispatch("Excel.Application").ActiveWorkbook.FullName)
    else:
        return None


input()
time.sleep(2)
print(get_file_path())

input()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions