Creating a shortcut in OSX

I am trying to create a shortcut to applications of my app. So I do the following

ln -s “myapp.app” /Applications/Myapp.app

This does not seem to work in OSX, fine in linux?

anyone any ideas why? is it to do with bundles?

If MBS plugins is an option for you then you may want to have a look at CFBookmarkMBS.WriteBookmarkDataToFile.

I’m using it in code to create an Alias (Shortcut) to an SQLite database file like this:

[code]Private Sub imFileCreateAliasToSQLite()
'******************************************************************
’ Last change: 09.02.2015
’ Author : Oliver Osswald
’ Purpose: Create a shortcut to a SQLite single user database
’ which is currently in use
'******************************************************************

// Store the reference to a FolderItem
Dim file As FolderItem = imDB.imDBProps.imDBFile

If file <> Nil And file.Exists Then
Dim fName As String = file.NameWithoutExtensionMBS

#If TargetCocoa
  
  Try
    
    Dim Bookmark As String = CFBookmarkMBS.CreateBookmarkData(file, CFBookmarkMBS.kCreationSuitableForBookmarkFile)
    
    Dim dlg as New SaveAsDialog
    Dim AliasFile As FolderItem
    dlg.InitialDirectory=SpecialFolder.Desktop
    dlg.promptText=arbStrings.Create_Shortcut
    dlg.SuggestedFileName=fName + " alias"
    dlg.Title=file.Name
    AliasFile=dlg.ShowModal()
    If AliasFile = Nil then
      //user canceled
      Return
    End if
    
    If AliasFile <> Nil then
      If Not CFBookmarkMBS.WriteBookmarkDataToFile(Bookmark, AliasFile, 0) Then
        Dim e As CFErrorMBS = CFBookmarkMBS.lasterror
        MsgBox arbStrings.Failed+" "+e.Description
      End If
    End if
  End Try
  
#EndIf

#If TargetWin32
  //Creates a shortcut (.lnk file) in the users %TEMP% directory named scName and pointing to scTarget. Returns
  //a FolderItem corresponding to the shortcut file. You must move the returned Shortcut file to the desired directory.
  //On error, returns Nil.
  
  Dim lnkObj As OLEObject
  Dim scriptShell As New OLEObject("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}")
  
  If scriptShell <> Nil then
    lnkObj = scriptShell.CreateShortcut(SpecialFolder.Desktop.AbsolutePath + fName + ".lnk")
    If lnkObj <> Nil then
      lnkObj.Description = fName.Uppercase
      lnkObj.TargetPath = file.AbsolutePath
      lnkObj.WorkingDirectory = file.AbsolutePath
      lnkObj.Save
    End If
  End If
#Endif

End If

End Sub
[/code]

[quote=208892:@dave duke]I am trying to create a shortcut to applications of my app. So I do the following

ln -s “myapp.app” /Applications/Myapp.app

This does not seem to work in OSX, fine in linux?

anyone any ideas why? is it to do with bundles?[/quote]

What you are attempting to create is a Symbolic link. But you got the syntax wrong. See
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ln.1.html

This works :

ln -s /Applications/Myapp.app Myapp.app

Note that symbolic links on Mac work because they are using the underlying Unix, but they are not the same thing as Aliases, which are a feature of Mac OS X itself. A symbolic link will break if you rename the target. An alias will not. The MBS plugin creates a true alias.

To add to Michel’s point, an alias will also track a target that’s moved within its volume whereas a symbolic link will not.

You had got the fucken parameters all messed up. Read the fucken manual :wink:

Is it not beautiful how certain profanities make it through the filters ? I was expecting !@#$% !

If you spell it right I’m sure it would :stuck_out_tongue:

You may be able to make a symlink to the executable and get it to launch.

I bow to your expertise, Sir. Please forgive the incorrigible frog from massacring your noble vernacular. I am so dumb as to believe what is posted on the Internet Urban Dictionary: fucken

Please enlighten the ignorant, and tell me the exact spelling of that particular profanity. I think if you post it as code, it will go through. Unless you mean it should not end in “en”, but rather in “ing” ? But would it not lose the flavor of street parlance ?

I did to TextEdit.app and it works perfectly. I use Symlinks extensively on my web sites.

I guess you’ll need to use some form of encoding, hex, oct?