Jump to content

AppScripts — List, search and run AppleScripts for the active application


Recommended Posts

  • 10 months later...
  • 11 months later...

Can't live without this workflow, but when I got a new MacBook I get the "alfred error in workflow permission denied er 13" message.  It still works on my other computer using the same Alfred preferences in Dropbox sync. Is this folder permission issue.  My Scripts folders seem to be both read/write permissible.  

Link to comment

This has happened with a few Alfred Workflow, including my favorites, Appscripts, Menu items, Window Switcher etc.  Upon upgrading my new MacBook Pro and syncing Alfred with my old Mac via shared Alfred preference file in Dropbox , the old Mac continued running workflows just fine.  I solved the new problem simply by re-downloading this and other workflows.  So, it works fine right now.  This seems to be a larger question about the sync function.  For instance my new Mac, when searching brings up every possible item/element of all my Alfred workflows (Preference file in Dropbox) including every single (.jason, .py, , png etc.) where as my other computer does not.  I realize this does not relate to your workflow but there is clearly a dropbox sync issue, that lead me to believe mistakenly it was your workflow.  Sorry about that.   

Link to comment
  • 11 months later...

Hi, just discovered the workflow (great work!) and installed. The problem I'm having is that it doesn't show me only the scripts for the active application, but shows me all scripts I have... I'm running under Mojave (10.14) and use Alfred3.

What am I doing wrong? Can somebody help?

Thanks in advance!

Link to comment

Thanks for the reaction deanishe, but after I have done that, I keep getting the message "no scripts for Alfred 3"...

 

My directories are configured as follows:

 

~/Library/Scripts/Applications/{app_name}

~/Library/Scripts/Applications/{bundle_id}

~/Library/Application Scripts/{app_name}

~/Library/Application Scripts/com.omnigroup.OmniFocus3.MacAppStore

~/Library/Application Support/DEVONthink Pro Office/Scripts

~/Library/Application Support/{bundle_id}/Scripts

~/Library/Containers/{bundle_id}/Data/Library/Application Support/{app_name}/Scripts

 

What am I still doing wrong?

 

Thanks for the continued support.

Link to comment

Apologies for the late response. Busy at work this week ?

 

Yes, I have followed the Alfred instructions....

 

When I just opened the appscript instruction I saw an update available, which I applied.

 

When I now run the .as command I do see the Omnifocus scripts but don't see the DEVONthink ones... And I see the Omnifocus scripts even when OmniFocus isn't active...

 

So, I just don't know anymore....

 

When I run with debugger, the script considers Alfred as the frontmost app, while I have changed to working for example to Omnifocus.. Makes sense because I am switching to Alfred when I activate the script....

Link to comment

Next update:

 

I have now hardcoded the app_name and bundle_id again in the directory list, and I do see the scripts now, but again I see them always. So back to the challenge of only seeing the scripts of OmniFocus when working in OmniFocus, or DevonThink when I am working with DT...

 

 

Link to comment
6 minutes ago, Qique said:

Makes sense because I am switching to Alfred when I activate the script....

 

Alfred should never be the active app. That's the way it's designed. It used to have an alternate mode where it did become the active app (it helped with multiple monitors), but that option seems to now be gone (perhaps @Andrew can confirm).

 

Have you tried setting the Hotkey in the workflow and running it that way? (I use ^⌘A).

 

Just now, Qique said:

I do see the scripts now, but again I see them always

 

You will if you've hardcoded a value.

 

16 minutes ago, Qique said:

When I run with debugger, the script considers Alfred as the frontmost app

 

Please post the full debugger output.

 

 

Link to comment
11 hours ago, deanishe said:

Alfred should never be the active app. That's the way it's designed. It used to have an alternate mode where it did become the active app (it helped with multiple monitors), but that option seems to now be gone (perhaps @Andrew can confirm).

 

Alfred still has the focus compatibility mode in Appearance > Options, but it's very rare that compatibility mode is needed these days (if you're up to date with macOS).

 

Setting this option to "Compatibility Mode" in Alfred will make Alfred the front most (focused) application in macOS while Alfred's window is visible.

Link to comment
  • 3 years later...
  • 7 months later...

I use this great workflow to run my own AppleScript. In some applications script folder, I have sub-folder that has the scripts.

 

How can this script be modified to a) search for these folder name b) include content of sub-folders when searching for script. 

 

I briefly looked at appscripts.py that is used for search. It has line that sets the folder and can possibly be updated to include sub-folder:

 

DEFAULT_PATHS_FILE = os.path.join(os.path.dirname(__file__),
                                  'Script Directories.default.txt')

 

Is the workflow still maintained? @deanishe @vitor for your kind response please.

Link to comment
2 hours ago, vitor said:

@pankajsz Don’t jump into script editing, read the instructions (top post). That file isn’t the directory, it lists them and is editable.

Thanks @vitor

 

Got Script Directories.default.txt instead of one mention in the instructions:

 

#--------------------------------------------------------------------
# Script Directories
#--------------------------------------------------------------------
# These directories will be searched for scripts.
#
# Files in these directories with extension .applescript, .scpt,
# .scptd or .js will be shown in results.
#
# Empty lines and lines starting with # will be ignored.
#
# Environmental variables and ~ will be expanded, so
# $HOME/Scripts and ~/Scripts will both expand to the "Scripts"
# directory in your home folder.
#
# In addition {app_name} and {bundle_id} will be replaced with
# the name and bundle ID of the currently active application.
#
# For example, if Safari is the active application,
# "~/Scripts/{app_name}" will be expanded to
# "/Users/username/Scripts/Safari"
#
# If you want certain scripts to be shown for *every* application,
# specify a path without {app_name} or {bundle_id} in the path.
# This will then always match.

#--------------------------------------------------------------------
# Default directories
#--------------------------------------------------------------------
~/Library/Scripts/Applications/{app_name}
~/Library/Scripts/Applications/{bundle_id}
~/Library/Application Scripts/{app_name}
~/Library/Application Scripts/{bundle_id}
~/Library/Application Support/{app_name}/Scripts
~/Library/Application Support/{bundle_id}/Scripts
~/Library/Containers/{bundle_id}/Data/Library/Application Support/{app_name}/Scripts

#--------------------------------------------------------------------
# Custom directories
#--------------------------------------------------------------------
 

I can add path to show for *every* application through this.

 

My request is for including sub-folder under {app_name}:

 

~/Library/Scripts/Applications/{app_name}/Sub-folderA

~/Library/Scripts/Applications/{app_name}/Sub-folderB

 

and gather it dynamically. I can move all scripts into {app_name} folder itself by removing sub-folder but it becomes difficult to read and manage more than 10-15 files.

 

thanks for your time

Link to comment

Do in a Terminal find -type d ~/Library/Scripts/Applications and you’ll get a nice list with all subdirectories. This one has been going for years without subdirectory support and is unlikely to change for now. There might be a reason the support isn’t there (e.g. hurting performance).

Link to comment
1 hour ago, vitor said:

Do in a Terminal find -type d ~/Library/Scripts/Applications and you’ll get a nice list with all subdirectories. This one has been going for years without subdirectory support and is unlikely to change for now. There might be a reason the support isn’t there (e.g. hurting performance).

Ok and thanks @vitor I will try this. If I add manually then the scripts will be available in all applications instead of just that specific applications? Number of Sub-directories is limited so performance is unlikely to get affected, I think. Is @deanishe original owner of this workflow still active?

Link to comment
  • 8 months later...
On 10/3/2022 at 5:02 AM, vitor said:

Do in a Terminal find -type d ~/Library/Scripts/Applications and you’ll get a nice list with all subdirectories. This one has been going for years without subdirectory support and is unlikely to change for now. There might be a reason the support isn’t there (e.g. hurting performance).

 

 

@vitor -- request for help to include sub-folder. The Python code is too long for me to understand and modify it correctly. 

 

Here is the chatGPT three suggestions that I tried but couldn't make it work

 

To modify the code so that scripts stored in sub-folders are also included, you need to make changes in the _get_scripts_for_app method. Here are the modifications you can make:

  1. Replace the line:

pythonCopy code

log.debug('loading scripts from `%s`...', scriptdir)

with:

pythonCopy code

log.debug('recursively loading scripts from `%s`...', scriptdir) 

  1. Replace the line:

pythonCopy code

for filename in os.listdir(scriptdir): 

with:

pythonCopy code

for root, _, filenames in os.walk(scriptdir): for filename in filenames: 

  1. Replace the line:

pythonCopy code

path = os.path.join(scriptdir, filename) 

with:

pythonCopy code

path = os.path.join(root, filename) 

 

By making these modifications, the code will recursively traverse the script directory and include scripts from all sub-folders as well.

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...