Flow-Launcher / Flow.Launcher

:mag: Quick file search & app launcher for Windows with community-made plugins
https://flowlauncher.com
MIT License
8.1k stars 317 forks source link

Enhancement: new builtin shortcuts: active_office_file #2936

Open 1208nn opened 2 months ago

1208nn commented 2 months ago

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()
github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 60 days.\n\nAlternatively this issue can be kept open by adding one of the following labels:\nkeep-fresh

github-actions[bot] commented 1 week ago

This issue was closed because it has been stale for 7 days with no activity. If you feel this issue still needs attention please feel free to reopen.