cherrytree icon indicating copy to clipboard operation
cherrytree copied to clipboard

[Mac] run as an app and not as CLI

Open cdamken opened this issue 3 years ago • 19 comments

Version, Operative system macOS Big Sur 11.2.3 (Latest)

Describe the bug Not sure if its a bug or should be a feature:

Normally the apps installed with brew are:

brew install --cask  App name

And then I have one app that I can run directly

In the Cherrytree app is only:

brew install cherrytree

Then I have to open a Terminal and run from there.

I can see it exist in other apps (as an example) :

https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/keepingyouawake.rb#L20

Am I missing something on how to install or run it?

Thanks in advance!

cdamken avatar Apr 09 '21 12:04 cdamken

I'm not familiar with what needs to be done in the Mac os to add the app to the desktop menu but I will investigate

giuspen avatar Apr 10 '21 15:04 giuspen

me too

fate93930 avatar Apr 13 '21 10:04 fate93930

Any update on that?

alfador1 avatar Apr 19 '21 09:04 alfador1

Not yet, will do some research in the next days see if I understand what is needed

giuspen avatar Apr 19 '21 18:04 giuspen

Thank's @giuspen

The problem here is, that the app has to kept running on the Terminal and does not appear as an app. and if the terminal is closed then the app crashes.

cdamken avatar Apr 22 '21 08:04 cdamken

Hi @giuspen, do you have some findings?

It's kind of annoying to have the terminal always opened

cdamken avatar May 07 '21 14:05 cdamken

To be honest I was hoping it was as easy as create something like a .desktop file for Linux and install it somewhere at the time of installing cherrytree buy I haven't found such thing. I found instead guides on adding command launchers to the panel and basically that's what you have to do, add a custom launcher/command with the command "cherrytree". I'll try myself and explain better but I need to fix some other stuff for the next release first

giuspen avatar May 08 '21 11:05 giuspen

Hi everyone!

I've done the installation through Homebrew and it does not create an .app file, it creates a regular bin in /usr/local/bin/cherrytree

You have to create an applescript in automator to create an .app and save it in the /Applications folder to it to appear in the launchpad.

The script needs only these three lines:

tell application "/usr/local/bin/cherrytree" activate end tell

If you don't want that ugly automator icon, you can change it in a lot of ways, or you can use an application called Platypus to create it and change the icon.

  1. After installing it you choose the name of the App you want (Cherrytree in this case)
  2. Change to applescript
  3. Click in new and paste the code above in the pop up and save it
  4. Change interface to none
  5. Change the icon to the one you want
  6. Change the identifier name
  7. Change the author's name

cherryscreen1

cherryscript

Save it in the Applications folder

cherryscreen2

And voilà, it is in the Launchpad!!

cherryscreen3

After you open it, it creates an icon in the dock with the icon you chose and no terminal window whatsoever!

Hope it helps!

bernardmotoni avatar May 15 '21 15:05 bernardmotoni

After my answer and a little reflection I think I should have inserted Giuseppe Penone as the author's name... 🤣🤣🤣

My bad @giuspen

bernardmotoni avatar May 15 '21 15:05 bernardmotoni

I've created a .app file with the original cherrytree icon with bigsur style and the proper credit to Giuseppe!!

Cherrytree.app.zip

bernardmotoni avatar May 15 '21 16:05 bernardmotoni

@bernardmotoni your help is very useful, do you think I may try and have your app file(s) installed somewhere on the filesystem in the homebrew install or the user will have to manually add it? I will give it a try anyway later on my Mac OSX Big Sur VM

giuspen avatar May 15 '21 20:05 giuspen

@giuspen Glad I could help!!! I don't know how to build the homebrew install, but a lot of those I install during the installation script they automatically copy the .app do the /Applications folder...

I'll check it out!

bernardmotoni avatar May 15 '21 22:05 bernardmotoni

Found this in the Homebrew issues... It's a script people use to remove an old version of the app in the App folder and copy the new one...

I can't test this one, but I think it's worth a try.

Copy applications #3888

version() { mdls -name kMDItemVersion "$1"| egrep -o [0-9.]+ ;}
App=(/App*s/"${1##*/}")

[[ ! -a $App || -L $App || $(version $1) > $(version $App) ]] &&
{   mv "$App" ~/.Trash
    mv "$1" "${App%/*}"
    ln -s "$App" "${1%/*}"/
}

bernardmotoni avatar May 18 '21 15:05 bernardmotoni

Thanks @bernardmotoni I'll try and do some testing on the launcher in the next days

giuspen avatar May 19 '21 21:05 giuspen

Thanks, @bernardmotoni, I get still a terminal icon in the dock, is there a way to prevent this?

dev-2-4-h avatar Jun 24 '21 09:06 dev-2-4-h

Thanks, @bernardmotoni, I get still a terminal icon in the dock, is there a way to prevent this?

R u ready for the workout? LOL

After some trial and error I found this:

You have to run the app, after it is in the dock, right click it -> options -> show in finder

Then it will open the folder containing the bin file. In my case, with the latest version, it was /usr/local/Cellar/cherrytree/0.99.38/bin

After that You'll right click cherrytree and click in Get Info.

In the info page you HAVE to change the permissions of the app to read and write for your user, admin and everyone.

Then you proceed to pick the icon of the cherrytree app and drag it into the "terminal icon" of the bin

If you don't have an icon to put, you can take the one I made inside the cherrytree.app and place it there.

Right click cherrytree.app and click in Show Package Content then go to Contents -> Resources and then you'll find a file called AppIcon.icns. This is the guy you want.

Drag it into the info dialog and you'll get the official cherrytree icon Big Sur style in your Dock.

Sorry for the long post. Hope it'll help.

bernardmotoni avatar Jun 24 '21 14:06 bernardmotoni

I just found out that the .zip I made was creating an .app inside a .app...

Remade it to work right..

CherryTree.zip

bernardmotoni avatar Jun 24 '21 14:06 bernardmotoni

In general on macOS, an application is just a folder in a specific format:

  /Applications/MacPorts/CherryTree.app/Contents/Info.plist
  /Applications/MacPorts/CherryTree.app/Contents/MacOS/CherryTree
  /Applications/MacPorts/CherryTree.app/Contents/PkgInfo
  /Applications/MacPorts/CherryTree.app/Contents/Resources/CherryTree.icns

The CherryTree executable can be the application, or a script that launches it. The icns file is obvious. The Info.plist file has a specific format. Here is the one we use on MacPorts for the python version of cherrytree. The c++ version would be very similar.

% cat  /Applications/MacPorts/CherryTree.app/Contents/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>CherryTree</string>
    <key>CFBundleIconFile</key>
    <string>CherryTree.icns</string>
    <key>LSUIElement</key>
    <true/>
    <key>CFBundleIdentifier</key>
    <string>com.github.giuspen.cherrytree.CherryTree</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>CherryTree</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>0.39.4</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>0.39.4</string>
</dict>
</plist>

The PkgInfo file is an ASCII file that is presently this:

APPL????

If you wanted to make a self-contained, relocatable version of cherrytree you would move all the linked libraries and similar needed resources into the Resources folder, and then tell the executable where to find them. This usually means relinking the executable using @rpath links to the needed libraries (changing these with install_name_tool). This can get tricky, so many people use dylibbundler:

% port info dylibbundler
dylibbundler @1.0.0 (devel)
Variants:             universal

Description:          dylibbundler is a small command-line programs that aims to make bundling .dylibs as easy as possible. It
                      automatically determines which dylibs are needed by your program, copies these libraries inside the app
                      bundle, and fixes both them and the executable to be ready for distribution, all this with a single
                      command. It will also work if your program uses plug-ins that have dependencies too.
Homepage:             https://github.com/auriamg/macdylibbundler

Platforms:            darwin
License:              MIT
Maintainers:          Email: [email protected], GitHub: ryandesign
                      Policy: openmaintainer

kencu avatar Aug 01 '21 14:08 kencu

I just found out that the .zip I made was creating an .app inside a .app...

Remade it to work right..

CherryTree.zip

Oh wow, this worked a treat for me! This should be added to the install process or https://giuspen.net/cherrytreemanual/

PhilAtKC avatar Aug 01 '22 16:08 PhilAtKC

Hi everyone!

I've done the installation through Homebrew and it does not create an .app file, it creates a regular bin in /usr/local/bin/cherrytree

You have to create an applescript in automator to create an .app and save it in the /Applications folder to it to appear in the launchpad.

The script needs only these three lines:

tell application "/usr/local/bin/cherrytree" activate end tell

If you don't want that ugly automator icon, you can change it in a lot of ways, or you can use an application called Platypus to create it and change the icon.

  1. After installing it you choose the name of the App you want (Cherrytree in this case)
  2. Change to applescript
  3. Click in new and paste the code above in the pop up and save it
  4. Change interface to none
  5. Change the icon to the one you want
  6. Change the identifier name
  7. Change the author's name

cherryscreen1

cherryscript

Save it in the Applications folder

cherryscreen2

And voilà, it is in the Launchpad!!

cherryscreen3

After you open it, it creates an icon in the dock with the icon you chose and no terminal window whatsoever!

Hope it helps!

Thank you for your help. I was able to successfully resolve my issue using the method you provided. It was both effective and convenient, and aligns well with the logic of macOS. I appreciate it.

thiswind avatar Dec 27 '22 06:12 thiswind

Open Automator on your Mac. Select "Application" as the type of document to create. In the search bar, type "Run AppleScript" and select it. In the newly added "Run AppleScript" box, copy and paste the following script:

tell application "/usr/local/bin/cherrytree" activate end tell

flamecopper avatar Jan 20 '23 01:01 flamecopper

In my case, the correct path was /opt/homebrew/bin/cherrytree

flexits avatar Feb 10 '23 16:02 flexits

Thanks, @bernardmotoni, I get still a terminal icon in the dock, is there a way to prevent this?

R u ready for the workout? LOL

After some trial and error I found this:

You have to run the app, after it is in the dock, right click it -> options -> show in finder

Then it will open the folder containing the bin file. In my case, with the latest version, it was /usr/local/Cellar/cherrytree/0.99.38/bin

After that You'll right click cherrytree and click in Get Info.

In the info page you HAVE to change the permissions of the app to read and write for your user, admin and everyone.

Then you proceed to pick the icon of the cherrytree app and drag it into the "terminal icon" of the bin

If you don't have an icon to put, you can take the one I made inside the cherrytree.app and place it there.

Right click cherrytree.app and click in Show Package Content then go to Contents -> Resources and then you'll find a file called AppIcon.icns. This is the guy you want.

Drag it into the info dialog and you'll get the official cherrytree icon Big Sur style in your Dock.

Sorry for the long post. Hope it'll help.

Now the final step left...

If you "keep it in dock", then once you open it via dock icon, it launches the terminal, rather than *.app

Now if you drag the app to the dock, once it is launched it opens new app, but closes the launcher.

Which is inconsistent with how all of my other apps work... :(

dg-pb avatar Jun 08 '23 04:06 dg-pb

There is any chance to insert directly in brew the app? (like other programs as VsCode)

Alfystar avatar Jun 21 '23 08:06 Alfystar

I found one solution with Automator: image

# No file selected execution
[[ -z "$@" ]] && exec /opt/homebrew/bin/cherrytree > /dev/null 2>&1 &

# Files selected execution 
for f in "$@"
do
   exec /opt/homebrew/bin/cherrytree "$f" > /dev/null 2>&1 &
done
exit 0

This setup permits running multiple instances with multiple files or no one.

To change the application icon, simply open information and drag and drop the icon over the default automator icon

Actually I'm studying how to add icon to all associated files

Alfystar avatar Jun 22 '23 10:06 Alfystar

Based on this solution: https://gist.github.com/philipptempel/6110875

  1. Open the CherryTree.app in finder with the second option (Show package continent)
  2. Paste the icon file of cherryTree (I download it from documentation) CherryTree.app/Contents/Resources/CherryTree.icns
  3. Edit CherryTree.app/Contents/Info.plist as follow:
    1. Search <key>CFBundleIconFile</key> and change the string parameter with ONLY the name of icon (here CherryTree)
    2. Search <key>CFBundleDocumentTypes</key>override the array tag with follow:
    	<key>CFBundleDocumentTypes</key>
    	<array>
    		<dict>
    			<key>CFBundleTypeExtensions</key>
    			<array>
    				<string>ctb</string>
    				<string>ctx</string>
    				<string>cbd</string>
    				<string>cbz</string>
    			</array>
    			<key>CFBundleTypeName</key>
    			<string>CherryTree note file</string>
    			<key>CFBundleTypeIconFile</key>
    			<string>CherryTree</string>
    			<key>CFBundleTypeOSTypes</key>
    			<array>
    				<string>****</string>
    			</array>
    			<key>CFBundleTypeRole</key>
    			<string>Viewer</string>
    		</dict>
    	</array>
    
  4. Now exit from the application folder (yes, in Mac applications are simply a folder), move the CherryTree.app to another folder, and then again in the Application folder (This is done so Launch Services picks up the changes to Info.plist we just performed.)

Now should see the application il launch pad and file with the .cbt extension change

Alfystar avatar Jun 22 '23 11:06 Alfystar