Flow.Launcher icon indicating copy to clipboard operation
Flow.Launcher copied to clipboard

Enhancement: new builtin shortcuts: active_office_file

Open 1208nn opened this issue 1 year ago • 0 comments

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()

1208nn avatar Aug 25 '24 09:08 1208nn