Jump to content

Change Default App for filetype


Recommended Posts

Posted (edited)

Dependencies

 

Default App uses duti to change assigned apps. 

You need to install duti first before you execute the Alfred Workflow

 

brew install duti

 

Usage

 

dapp ext

 

1. ext you can type any extension, the workflow will ask for confirmation to change the assigned app
2. Choose one of the Apps to assign the extension to.

 

Download on Git

 

https://github.com/Acidham/alfred-default-app

Edited by Acidham
Posted
7 hours ago, xilopaint said:

Why don't you use a Script Filter for the second step?

 

Because it was too late yesterday. 😂

 

Version 1.0 is now available and ported to Python 🤗

 

I hope there is no new bug 🤨 ... let me know how it goes...

Posted
4 minutes ago, deanishe said:

Where did you get Alfred.py from? That's some really old-school looking code.

 

Thanks 😢

I created for my own once I started with Python&Alfred. Since it does the Job I never touched it...even if I am not sure if I ever can write high-polished code 😕

 

Posted (edited)
19 minutes ago, Acidham said:

Thanks 😢

 

I didn't say, and certainly didn't mean, "bad".

 

I just asked because of the old-style classes. I think most Python programmers these days don't even know they exist.

 

There's absolutely nothing wrong with the code. The style is just kinda old-school (old-style classes, camelCase).

Edited by deanishe
Posted
Just now, deanishe said:

I just asked because of the old-style classes. I think most Python programmers these days don't even know they exist.

 

😳 really? can you point me to newer-style format or at least what old-style is in my class? Now you made me curious ;) 

 

...and, no worries, every feedback is welcome hand helps...thx for that!

Posted (edited)
25 minutes ago, Acidham said:

can you point me to newer-style format or at least what old-style is in my class?

 

New-style classes inherit from object, e.g. class Item(object):. I don't remember what difference it actually makes (other than Python 3 doesn't support old-style classes), just that in about 2002 they said "you should use new-style classes from now on." Here are the technical details.

 

Similarly, PEP 8, the official Python style guide came out in 2001 and said that we should all use PascalCase for class names and snake_case for everything else. So you tend to only see camelCase in very old code (like plistlib.readPlist from the standard library, or the Twisted library, which has also been around forever).

Edited by deanishe
Posted

Ok got it, but this is mostly based coincidences. 

 

For class Item(object) I did not saw the need therefore I ignored it :D

 

I started with snake_case but then I felt a bit lost aka I was not able to see the differences between variables and methods so I switch to PascalCase. But now I am on the way to switch to snake_case. Furthermore PyCharm always notified me about my old style 😕

 

Thank you for your pointers! I made now the decision to take care of the new_style in the future!

Posted

Hey,

 

It doesn't seem to work by my side.

Entering dapp just returns a contact that I've saved as such, but entering a file extension ater it does nothing.

 

Am I missing a step ?

Posted (edited)

Did you install duti ?

 

Any WF debug Info when executing ?

Edited by Acidham
  • 4 years later...
Posted (edited)

@Acidham `operation not permitted: ./py3.sh` is what I get when trigger the workflow and typing in the extension name. I checked that py3.sh has execute perms

 

duti is installed

Edited by andy4222
Posted

py3.sh is checking for the latest version of python3. You can easily comment that out for time being in the workflow steps:


e.g.


# ./py3.sh ext.py "$1"
python3 ext.py "$1"


 

Can you also send me the python3 version you are using?

Posted

@Acidham You’re probably better off just removing the file and using /usr/bin/python3 directly, no need for the middleman (er, middlescript?)

 

jKkpjy0.png

 

Or even just using External Script directly.

 

4c48NPi.png

 

I have confirmed both work in Ventura.

Posted (edited)

@vitor yep that is the plan to get rid of py3.sh. Meanwhile, it should work with python3. But first I wanted to get confirmation.

Edited by Acidham
  • 5 months later...
Posted

Hi,
I used This so nice workflow for months, but now it doesn't work in My MacBook pro (m1pro, Sonoma os). Any help, please?
This is the debug report:

[19:47:30.080] Default App[Script Filter] Processing complete
[19:47:30.085] Default App[Script Filter] Passing output 'PDF Studio Viewer 2023' to Arg and Vars
[19:47:30.087] Default App[Arg and Vars] Processing complete
[19:47:30.088] Default App[Arg and Vars] Passing output 'PDF Studio Viewer 2023=.pdf' to Run Script
[19:47:30.246] ERROR: Default App[Run Script] Traceback (most recent call last):
  File "/Users/farisal-mawwashi/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.60FD7BEC-4973-4B4C-A1F1-6638DA93FADC/change.py", line 37, in <module>
    resp = duti(app_id, ext)
           ^^^^^^^^^^^^^^^^^
  File "/Users/farisal-mawwashi/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.60FD7BEC-4973-4B4C-A1F1-6638DA93FADC/change.py", line 28, in duti
    resp = os.system(f"{d_path} -s " + appid + " " + ext + " all")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: embedded null byte
[19:47:30.260] Default App[Run Script] Processing complete
[19:47:30.261] Default App[Run Script] Passing output '' to Debug
[19:47:30.262] Default App[Debug] '', {
  ext = ".pdf"
}
[19:47:30.264] Default App[Debug] Processing complete
[19:47:30.265] Default App[Debug] Passing output '' to Post Notification

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...